SPOT TAPE
FRNT-200K2.180+1.42%
MID-128K0.4204−0.81%
OW-70B0.0840+3.11%
OW-8B0.0191+0.44%
VIS-1M1.6400−2.19%
RSN-XL6.9000+0.93%
EMB-S0.01100.00%
14:02:07 UTC
Documentation v1 · UPDATED 21 AUG 2026
Get an API key

Error handling

Map code on the JSON body to a typed SDK error.

codemeaning
seller_unreachableWinning seller timed out or 5xx
bid_timeoutNo match before the wait expired
rate_limitedBuyer key exceeded burst
insufficient_balanceLedger rejected the trade
use token_gateway_sdk::{BuyerChatMessage, BuyerClient, BuyerKey, ChatCompletionsRequest, SdkError};

let client = BuyerClient::new("http://127.0.0.1:8080", BuyerKey("sk-buyer".into()));
match client
    .chat_completions(&ChatCompletionsRequest {
        model: "gpt-4".into(),
        messages: vec![BuyerChatMessage {
            role: "user".into(),
            content: "hello".into(),
        }],
        stream: false,
        max_price: None,
        temperature: None,
        max_tokens: None,
    })
    .await
{
    Ok(_) => {}
    Err(SdkError::Gateway { code, .. }) => {
        let _ = code;
    }
    Err(_) => {}
}
from token_gateway import BuyerAuth, BuyerTokenGateway, NoMatchError, RateLimitError

gw = BuyerTokenGateway("http://127.0.0.1:8080", buyer=BuyerAuth("sk-buyer"))
try:
    gw.chat_completions(model="gpt-4", messages=[{"role": "user", "content": "hello"}], max_price="0.05")
except NoMatchError as exc:
    print(exc.code)
except RateLimitError as exc:
    print(exc.code)
import { BuyerClient, NoMatchError, RateLimitError } from "@ai-token-gateway/sdk";

const buyer = new BuyerClient({ baseUrl: "http://127.0.0.1:8080", apiKey: "sk-buyer" });
try {
  await buyer.chatCompletions({
    model: "gpt-4",
    messages: [{ role: "user", content: "hello" }],
    max_price: "0.05",
  });
} catch (err) {
  if (err instanceof NoMatchError || err instanceof RateLimitError) {
    console.log(err.code);
  }
}