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

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/sdk
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://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/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_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,
});
MethodRoute
registerPOST /v1/register (public)
setApiKeysets X-Seller-API-Key for later calls
createOfferPOST /v1/offers
listOffersGET /v1/offers
cancelOfferDELETE /v1/offers/{offer_id}
getProfileGET /v1/profile
getReputationGET /v1/reputation
reportCapacityPOST /v1/capacity
listTradesGET /v1/trades
listDeliveriesGET /v1/sellers/{id}/deliveries

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