Documentation v1 · UPDATED 21 AUG 2026
Get an API key
On this page

TypeScript SDK

Package: @ai-token-gateway/sdk. Path in this repo: sdks/typescript/. Not on npm yet.

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

# from the Spot repository
cd sdks/typescript && npm ci
import { 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://api.aispotmarket.com",
  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}/configgatewayApiUrl):

const buyer = await BuyerClient.fromConfig(process.env.GATEWAY_CONFIG_URL!, process.env.BUYER_API_KEY!);
MethodRoute
chatCompletionsPOST /v1/chat/completions
chatCompletionsStreamsame, SSE (AsyncIterable)
streamWithEventSourcebrowser EventSource fallback
buy / wait / spend / replenishcapacity tickets

Seller

import { SellerClient } from "@ai-token-gateway/sdk";

const seller = new SellerClient({
  baseUrl: process.env.SPOT_API_URL ?? "https://api.aispotmarket.com",
});
const registered = await seller.register({
  name: "acme",
  endpoint_url: "https://seller.example/infer",
  supported_models: ["gpt-4"],
  api_key: "sk-seller",
});
seller.setApiKey(registered.api_key);
await seller.submitAsk(registered.seller_id, {
  model_id: "gpt-4",
  price: "0.05",
  capacity: 1000,
});
MethodRoute
registerPOST /v1/sellers/register (public)
setApiKeysets X-Seller-API-Key for later calls
submitAskPOST /v1/sellers/{id}/asks
cancelAskDELETE /v1/sellers/{id}/asks/{ask_id}
reportCapacityPOST /v1/sellers/{id}/capacity
listTradesGET /v1/sellers/{id}/trades
listDeliveriesGET /v1/sellers/{id}/deliveries

Errors are typed subclasses of GatewayError (NoFillAtLimitError, RateLimitError, …). See Errors. Telemetry is off by default — schema.