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?;| Method | Route |
|---|---|
chat_completions | POST /v1/chat/completions |
chat_completions_stream | same, SSE |
buy / get_order / wait / spend / replenish | capacity tickets |
token_gateway_sdk::health | GET /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?;| Method | Route |
|---|---|
register | POST /v1/register (public) |
set_key | sets X-Seller-API-Key for later calls |
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 |
Errors are SdkError. Wire codes map through GatewayErrorCode. See Errors. Telemetry is off by default — schema.