SDKs
Official Flexprice client libraries wrap the REST API and handle authentication, retries, idempotency key generation, and typed request/response objects.
All SDKs are open source on GitHub. Found a bug? Open an issue.
Node.js / TypeScript
Install via npm or yarn. Includes TypeScript types for all request and response objects.
npm install @flexprice/sdk
yarn add @flexprice/sdk
Initialization
import Flexprice from '@flexprice/sdk';
const client = new Flexprice({
apiKey: process.env.FLEXPRICE_API_KEY,
});
Ingest an event
await client.events.ingest({
event_name: 'api.call',
customer_id: 'cust_abc123',
idempotency_key: crypto.randomUUID(),
properties: { tokens: 1024, model: 'gpt-4o' },
});
List invoices
const invoices = await client.invoices.list({
customer_id: 'cust_abc123',
status: 'open',
});
console.log(invoices.data);
Python
Requires Python 3.9+. Sync and async clients available.
pip install flexprice
Initialization
import flexprice
import os
client = flexprice.Client(api_key=os.environ["FLEXPRICE_API_KEY"])
Ingest an event
import uuid
client.events.ingest(
event_name="api.call",
customer_id="cust_abc123",
idempotency_key=str(uuid.uuid4()),
properties={"tokens": 1024, "model": "gpt-4o"},
)
Async client
from flexprice import AsyncClient
async_client = AsyncClient(api_key=os.environ["FLEXPRICE_API_KEY"])
await async_client.events.ingest(
event_name="api.call",
customer_id="cust_abc123",
idempotency_key=str(uuid.uuid4()),
)
Go
Requires Go 1.20+. Context-aware client with built-in retry and timeout handling.
go get github.com/flexprice/flexprice-go
Initialization
package main
import (
"context"
"os"
fp "github.com/flexprice/flexprice-go"
)
client := fp.New(os.Getenv("FLEXPRICE_API_KEY"))
Ingest an event
ctx := context.Background()
_, err := client.Events.Ingest(ctx, &fp.EventParams{
EventName: "api.call",
CustomerID: "cust_abc123",
IdempotencyKey: uuid.New().String(),
Properties: map[string]any{"tokens": 1024},
})
if err != nil {
log.Fatal(err)
}
Ruby
Requires Ruby 3.1+. Available as a gem.
gem install flexprice
Initialization and usage
require 'flexprice'
client = Flexprice::Client.new(api_key: ENV['FLEXPRICE_API_KEY'])
client.events.ingest(
event_name: 'api.call',
customer_id: 'cust_abc123',
idempotency_key: SecureRandom.uuid,
properties: { tokens: 1024, model: 'gpt-4o' }
)
Java
Requires Java 11+. Available on Maven Central.
<dependency>
<groupId>org.flexprice</groupId>
<artifactId>flexprice-java</artifactId>
<version>1.0.0</version>
</dependency>
Initialization and usage
import org.flexprice.FlexpriceClient;
FlexpriceClient client = FlexpriceClient.builder()
.apiKey(System.getenv("FLEXPRICE_API_KEY"))
.build();
client.events().ingest(EventRequest.builder()
.eventName("api.call")
.customerId("cust_abc123")
.idempotencyKey(UUID.randomUUID().toString())
.build());