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

Python SDK

Package: token-gateway. Import: token_gateway. Not yet published to PyPI — this page documents the API the package will present. To call Spot today, see Clients.

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

Not available yet. When the package ships it will install as:

pip install token-gateway
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://aispotmarket.com/buy/api"),
    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_SELLER_API_URL", "https://aispotmarket.com/sell/api"))
seller = gw.register_seller(
    name="acme",
    endpoint_url="https://seller.example/infer",
    supported_models=["gpt-4"],
    regions=["global"],
    api_key="sk-seller",
)
# price_per_million_tokens is per one MILLION tokens.
gw.create_offer(model="gpt-4", price_per_million_tokens="0.05", quantity_tokens=1000)
MethodRoute
register_sellerPOST /v1/register (public)
create_offerPOST /v1/offers
list_offersGET /v1/offers
cancel_offerDELETE /v1/offers/{offer_id}
get_profileGET /v1/profile
get_reputationGET /v1/reputation
report_capacityPOST /v1/capacity
list_tradesGET /v1/trades
list_deliveriesGET /v1/deliveries

submit_ask and cancel_ask remain as deprecated aliases. They take a price per one thousand tokens and convert it before sending; prefer create_offer and cancel_offer, which use the API's own price_per_million_tokens.

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