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/pythonfrom 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"]),
)| 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_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)| Method | Route |
|---|---|
register_seller | POST /v1/sellers/register (public) |
submit_ask | POST /v1/sellers/{id}/asks |
cancel_ask | DELETE /v1/sellers/{id}/asks/{ask_id} |
report_capacity | POST /v1/sellers/{id}/capacity |
list_trades | GET /v1/sellers/{id}/trades |
list_deliveries | GET /v1/sellers/{id}/deliveries |
Errors are GatewayError subclasses (NoFillAtLimitError, RateLimitError, …). See Errors. Telemetry is off by default — schema.