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

Chat completions

POST https://aispotmarket.com/buy/api/v1/chat/completions

Spot accepts the common OpenAI chat-completions envelope and adds one routing field, max_price. The Gateway removes max_price and forwards the remaining request body to the selected seller. Market admission currently requires string message content, so multipart content arrays and other newer OpenAI shapes are not part of the guaranteed contract.

The live gateway matches the bid against the model book, dispatches to the winning seller, and returns a standard chat-completion body.

Auth: Bearer buyer key.

See also rate limits, errors, and response consumption.

Spot parameter

fieldtypenotes
max_pricedecimal string, optionalMaximum price per 1,000 tokens. Requests that cannot fill at or below it return 402. Omitting it submits an uncapped immediate bid; it does not use the midpoint or an account-level default.
modelstring, requiredAn instrument string, not a vendor model name. See Instruments.

region and venue_pin are not chat-routing fields. Region remains a filter for capacity orders and market-data views; seller selection for chat uses the instrument book and max_price.

Request

fieldtypenotes
modelstringInstrument / model id
messages{role, content}[]OpenAI chat turns
max_pricedecimal stringMax price per 1,000 tokens
max_tokensnumberOptional generation cap
temperaturenumberOptional sampling
streamboolSSE when true

Response

For stream=false, Spot returns the selected seller's OpenAI-shaped chat.completion JSON. For stream=true, Spot streams the seller's SSE bytes without routing them through Market. Spot does not add a top-level response object; use trade history for execution records.

Errors

Call now (account key): no_fill_at_limit, rate_limited, seller_unreachable, insufficient_balance, unauthorized.

Spend (ticket credential): contract_exhausted, seller_default, contract_expired, contract_not_yet_deliverable. Status codes on Errors.

curl -s http://127.0.0.1:8080/v1/chat/completions \
  -H "Authorization: Bearer sk-buyer" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4","messages":[{"role":"user","content":"hello"}],"stream":false,"max_price":"0.05","temperature":0.2,"max_tokens":128}'
use token_gateway_sdk::{BuyerChatMessage, BuyerClient, BuyerKey, ChatCompletionsRequest};
// {"model":"gpt-4","messages":[{"role":"user","content":"hello"}],"stream":false,"max_price":"0.05","temperature":0.2,"max_tokens":128}

let client = BuyerClient::new("http://127.0.0.1:8080", BuyerKey("sk-buyer".into()));
let response = 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: Some(128),
    })
    .await?;
let _ = response.choices[0].message.content.clone();
# {"model":"gpt-4","messages":[{"role":"user","content":"hello"}],"stream":false,"max_price":"0.05","temperature":0.2,"max_tokens":128}
from token_gateway import BuyerAuth, BuyerTokenGateway

gw = BuyerTokenGateway("http://127.0.0.1:8080", buyer=BuyerAuth("sk-buyer"))
print(gw.chat_completions(
    model="gpt-4",
    messages=[{"role": "user", "content": "hello"}],
    max_price="0.05",
    temperature=0.2,
    max_tokens=128,
))
// {"model":"gpt-4","messages":[{"role":"user","content":"hello"}],"stream":false,"max_price":"0.05","temperature":0.2,"max_tokens":128}
import { BuyerClient } from "@ai-token-gateway/sdk";

const buyer = new BuyerClient({ baseUrl: "http://127.0.0.1:8080", apiKey: "sk-buyer" });
const res = await buyer.chatCompletions({
  model: "gpt-4",
  messages: [{ role: "user", content: "hello" }],
  max_price: "0.05",
  temperature: 0.2,
  max_tokens: 128,
});
console.log(res.choices[0].message.content);