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

Rust SDK

Crate: token-gateway-sdk. Not yet published to crates.io — this page documents the API the crate will present. To call Spot today, see Clients.

Use this when you are writing a new Rust integration. The official CLI (aispot) is a clap front-end over this crate — application code should depend on the crate, not on aispot. If you only need a one-shot call, use the CLI. Full map: Clients.

Install

Not available yet. When the crate ships it will be added as:

token-gateway-sdk = "1"
use token_gateway_sdk::{BuyerClient, BuyerKey, SellerClient};

Buyer

use token_gateway_sdk::{BuyerChatMessage, BuyerClient, BuyerKey, ChatCompletionsRequest, Decimal};

let client = BuyerClient::new(
    std::env::var("SPOT_API_URL")
        .unwrap_or_else(|_| "https://aispotmarket.com/buy/api".into()),
    BuyerKey(std::env::var("SPOT_API_KEY").expect("SPOT_API_KEY")),
);
let response = client
    .chat_completions(&ChatCompletionsRequest {
        model: "gpt-4".into(),
        messages: vec![BuyerChatMessage {
            role: "user".into(),
            content: "hello".into(),
        }],
        stream: false,
        max_price: Some(Decimal::new(5, 2)),
        temperature: None,
        max_tokens: Some(64),
    })
    .await?;
println!("{}", response.choices[0].message.content);

Local / staging discovery:

let client = BuyerClient::from_config(
    std::env::var("GATEWAY_CONFIG_URL").expect("GATEWAY_CONFIG_URL"),
    BuyerKey(std::env::var("BUYER_API_KEY").expect("BUYER_API_KEY")),
)
.await?;
MethodRoute
chat_completionsPOST /v1/chat/completions
chat_completions_streamsame, SSE
buy / get_order / wait / spend / replenishcapacity tickets
token_gateway_sdk::healthGET /health (also aispot health)

Seller

use token_gateway_sdk::{
    CreateSellerOfferRequest, Decimal, RegisterSellerRequest, SellerClient, SellerKey,
};

let mut client = SellerClient::new(
    std::env::var("SPOT_SELLER_API_URL")
        .unwrap_or_else(|_| "https://aispotmarket.com/sell/api".into()),
    None,
);
let registered = client
    .register(&RegisterSellerRequest {
        name: "acme".into(),
        endpoint_url: "https://seller.example/infer".into(),
        supported_models: vec!["gpt-4".into()],
        regions: Some(vec!["global".into()]),
        api_key: "sk-seller".into(),
    })
    .await?;
client.set_key(SellerKey(registered.api_key.clone()));
client
    .create_offer(
        &CreateSellerOfferRequest {
            model: "gpt-4".into(),
            region: "global".into(),
            // price_per_million_tokens is per one MILLION tokens.
            price_per_million_tokens: Decimal::new(5, 2),
            quantity_tokens: 1000,
            valid_for_seconds: 300,
            tenor: None,
        },
    )
    .await?;
MethodRoute
registerPOST /v1/register (public)
set_keysets X-Seller-API-Key for later calls
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

Errors are SdkError. Wire codes map through GatewayErrorCode. See Errors. Telemetry is off by default — schema.