Rust SDK
Crate: token-gateway-sdk. Path in this repo: token-gateway-sdk/. Not on crates.io yet.
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
# workspace path
token-gateway-sdk = { path = "../token-gateway-sdk" }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://api.aispotmarket.com".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::{Decimal, RegisterSellerRequest, SellerClient, SellerKey, SubmitAskRequest};
let mut client = SellerClient::new(
std::env::var("SPOT_API_URL").unwrap_or_else(|_| "https://api.aispotmarket.com".into()),
None,
);
let registered = client
.register(&RegisterSellerRequest {
name: "acme".into(),
endpoint_url: "https://seller.example/infer".into(),
supported_models: vec!["gpt-4".into()],
api_key: "sk-seller".into(),
})
.await?;
client.set_key(SellerKey(registered.api_key.clone()));
client
.submit_ask(
registered.seller_id,
&SubmitAskRequest {
model_id: "gpt-4".into(),
price: Decimal::new(5, 2),
capacity: 1000,
ttl_seconds: Some(300),
delivery: None,
},
)
.await?;| Method | Route |
|---|---|
register | POST /v1/sellers/register (public) |
set_key | sets X-Seller-API-Key for later calls |
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 SdkError. Wire codes map through GatewayErrorCode. See Errors. Telemetry is off by default — schema.