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

Python SDK

Package: token-gateway. Import: token_gateway. Path in this repo: sdks/python/. Not on PyPI yet.

Use this when you are writing a new Python integration. If the app already uses the OpenAI Python SDK, change the base URL instead. For scripts, use the aispot CLI. Full map: Clients.

Install

pip install -e sdks/python
from token_gateway import BuyerAuth, BuyerTokenGateway, SellerTokenGateway

BuyerTokenGateway / SellerTokenGateway are sync. AsyncBuyerTokenGateway / AsyncSellerTokenGateway are the async twins with the same methods.

Buyer

import os
from token_gateway import BuyerAuth, BuyerTokenGateway

gw = BuyerTokenGateway(
    os.environ.get("SPOT_API_URL", "https://api.aispotmarket.com"),
    buyer=BuyerAuth(os.environ["SPOT_API_KEY"]),
)
completion = gw.chat_completions(
    model="gpt-4",
    messages=[{"role": "user", "content": "hello"}],
    max_price="0.05",
    max_tokens=64,
)
print(completion.choices[0].message.content)

Local / staging discovery:

gw = BuyerTokenGateway.from_config(
    os.environ["GATEWAY_CONFIG_URL"],
    buyer=BuyerAuth(os.environ["BUYER_API_KEY"]),
)
MethodRoute
chat_completionsPOST /v1/chat/completions
chat_completions_streamsame, SSE
ticket helperstoken_gateway.tickets (buy / wait / spend)

Seller

import os
from token_gateway import SellerTokenGateway

gw = SellerTokenGateway(os.environ.get("SPOT_API_URL", "https://api.aispotmarket.com"))
seller = gw.register_seller(
    name="acme",
    endpoint_url="https://seller.example/infer",
    supported_models=["gpt-4"],
    api_key="sk-seller",
)
gw.submit_ask(seller.seller_id, model_id="gpt-4", price="0.05", capacity=1000)
MethodRoute
register_sellerPOST /v1/sellers/register (public)
submit_askPOST /v1/sellers/{id}/asks
cancel_askDELETE /v1/sellers/{id}/asks/{ask_id}
report_capacityPOST /v1/sellers/{id}/capacity
list_tradesGET /v1/sellers/{id}/trades
list_deliveriesGET /v1/sellers/{id}/deliveries

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