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 ciimport { 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}/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_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,
});| Method | Route |
|---|---|
register | POST /v1/sellers/register (public) |
setApiKey | sets X-Seller-API-Key for later calls |
submitAsk | POST /v1/sellers/{id}/asks |
cancelAsk | DELETE /v1/sellers/{id}/asks/{ask_id} |
reportCapacity | POST /v1/sellers/{id}/capacity |
listTrades | GET /v1/sellers/{id}/trades |
listDeliveries | GET /v1/sellers/{id}/deliveries |
Errors are typed subclasses of GatewayError (NoFillAtLimitError, RateLimitError, …). See Errors. Telemetry is off by default — schema.