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-gatewayfrom 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"]),
)| Method | Route |
|---|---|
chat_completions | POST /v1/chat/completions |
chat_completions_stream | same, SSE |
| ticket helpers | token_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)| Method | Route |
|---|---|
register_seller | POST /v1/register (public) |
create_offer | POST /v1/offers |
list_offers | GET /v1/offers |
cancel_offer | DELETE /v1/offers/{offer_id} |
get_profile | GET /v1/profile |
get_reputation | GET /v1/reputation |
report_capacity | POST /v1/capacity |
list_trades | GET /v1/trades |
list_deliveries | GET /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.