TypeScript SDK
Package: @ai-token-gateway/sdk. Not yet published to npm — this page documents the API the package will present. To call Spot today, see Clients.
Use this when you are writing a new TypeScript integration. If the app already calls OpenAI Chat Completions, change the base URL instead. For scripts, use the aispot CLI. Full map: Clients.
Install
Not available yet. When the package ships it will install as:
npm install @ai-token-gateway/sdkimport { BuyerClient, SellerClient } from "@ai-token-gateway/sdk";Buyer
import { BuyerClient } from "@ai-token-gateway/sdk";
const buyer = new BuyerClient({
baseUrl: process.env.SPOT_API_URL ?? "https://aispotmarket.com/buy/api",
apiKey: process.env.SPOT_API_KEY!,
});
const completion = await buyer.chatCompletions({
model: "gpt-4",
messages: [{ role: "user", content: "hello" }],
max_price: "0.05",
});
console.log(completion.choices[0].message.content);
Local / staging discovery (GET {url}/v1/config → gatewayApiUrl):
const buyer = await BuyerClient.fromConfig(process.env.GATEWAY_CONFIG_URL!, process.env.BUYER_API_KEY!);| Method | Route |
|---|---|
chatCompletions | POST /v1/chat/completions |
chatCompletionsStream | same, SSE (AsyncIterable) |
streamWithEventSource | browser EventSource fallback |
buy / wait / spend / replenish | capacity tickets |
Seller
import { SellerClient } from "@ai-token-gateway/sdk";
const seller = new SellerClient({
baseUrl: process.env.SPOT_SELLER_API_URL ?? "https://aispotmarket.com/sell/api",
});
const registered = await seller.register({
name: "acme",
endpoint_url: "https://seller.example/infer",
supported_models: ["gpt-4"],
regions: ["global"],
api_key: "sk-seller",
});
seller.setApiKey(registered.api_key);
// price_per_million_tokens is per one MILLION tokens.
await seller.createOffer({
model: "gpt-4",
price_per_million_tokens: "0.05",
quantity_tokens: 1000,
valid_for_seconds: 300,
});| Method | Route |
|---|---|
register | POST /v1/register (public) |
setApiKey | sets X-Seller-API-Key for later calls |
createOffer | POST /v1/offers |
listOffers | GET /v1/offers |
cancelOffer | DELETE /v1/offers/{offer_id} |
getProfile | GET /v1/profile |
getReputation | GET /v1/reputation |
reportCapacity | POST /v1/capacity |
listTrades | GET /v1/trades |
listDeliveries | GET /v1/sellers/{id}/deliveries |
Errors are typed subclasses of GatewayError (NoFillAtLimitError, RateLimitError, …). See Errors. Telemetry is off by default — schema.