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
| field | type | notes |
|---|---|---|
max_price | decimal string, optional | Maximum 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. |
model | string, required | An 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
| field | type | notes |
|---|---|---|
model | string | Instrument / model id |
messages | {role, content}[] | OpenAI chat turns |
max_price | decimal string | Max price per 1,000 tokens |
max_tokens | number | Optional generation cap |
temperature | number | Optional sampling |
stream | bool | SSE 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);