Response metadata: the request id and the cost of each call
Every response on /v1, /anthropic and /gemini, served or failed, carries an X-Request-Id header: 1xAi's own id of that call, the same id the usage report, the CSV export and the wallet transaction show. A successful, non-streamed answer of a billed route also carries X-1xai-Cost-Toman: what the call was billed, in Toman, markup included. The cost of a streamed call is read after the stream ends, by that id, from GET /v1/usage.
Last updated:
The request id: X-Request-Id
HTTP/1.1 200 OK Content-Type: application/json X-Request-Id: gw_01JD3Z5T8Q0V6W4M2K9R7N1PXA X-1xai-Request-Id: gw_01JD3Z5T8Q0V6W4M2K9R7N1PXA X-1xai-Cost-Toman: 158 X-RateLimit-Limit: 1000 X-RateLimit-Remaining: 999 X-RateLimit-Reset: 1
- Every answer on
/v1(the account API included),/anthropicand/geminicarries exactly oneX-Request-Id, whether the request was served or refused: a401,402,403,404or429, an error relayed from the model's vendor, and a502or504of the gateway's own all carry it. - Its value is 1xAi's own id of the call:
gw_followed by 26 characters, 29 in all. It is never a vendor's id, and a vendor's ownX-Request-Idis not forwarded. - On
/anthropic, when Anthropic sent aRequest-Idheader, the answer carries it too, with the same 1xAi id. So_request_idin the Anthropic and OpenAI SDKs is the id you give support. - It is the same id as: the
request_idof the call's row inGET /v1/usageand the value itsrequest_id=filter takes, therequest_idcolumn of the CSV export, the request id the dashboard's call log shows on an opened row (and finds in its search box), and thereferenceof the call's charge inGET /v1/wallet/transactions(account API). - The
X-1xai-Request-Idheader, with the same value, is still sent. - The id of a
POST /v1/realtime/client_secretanswer names that request only; the calls of a voice session have usage rows with ids of their own (rt_…) (realtime voice).
from openai import OpenAI
client = OpenAI(base_url="https://1xai.ir/v1", api_key="1xai-...")
raw = client.chat.completions.with_raw_response.create(
model="gpt-5.5",
messages=[{"role": "user", "content": "Hello"}],
)
print(raw.headers.get("x-request-id")) # gw_…
print(raw.headers.get("x-1xai-cost-toman")) # the amount in Toman
completion = raw.parse()The cost of the call: X-1xai-Cost-Toman
The amount this call was billed, in Toman: the price with 1xAi's markup, equal to the cost_toman of the call's row in the usage report. A plain number without thousands separators (in practice a whole number, since charges are whole Toman), whichever balance paid it: plan credit, gift credit or the wallet. A picture paid by a free trial states 0 (billing).
| Route | When |
|---|---|
POST /v1/chat/completions, /v1/completions, /v1/responses, /v1/embeddings | When:A 2xx answer, not streamed |
POST /v1/messages, /anthropic/v1/messages | When:A 2xx answer, not streamed |
POST /gemini/v1beta/models/{model}:generateContent | When:A 2xx answer |
POST /v1/images/generations, /v1/images/edits, /v1/images/variations | When:A 2xx answer |
POST /v1/audio/transcriptions, /v1/audio/translations, /v1/audio/speech | When:A 2xx answer |
- No streamed answer (
"stream": true,:streamGenerateContent) carries it: the headers are sent before the answer exists. The next section has the way. - No answer with a status of
400or above carries it, not even0: a refused or failed call is billed nothing. - Routes that only start a job whose cost is settled later do not carry it:
/v1/videos, Gemini's:predictLongRunningand/interactions, Anthropic message batches, OpenAI batches (POST /v1/batches) and realtime voice. Their cost is in their rows ofGET /v1/usage. - Free routes do not carry it:
/v1/moderations, token counts,/v1/models, the account API and the/v1/filesroutes. - No event of a stream is changed, and none is added.
Treat the header as optional
Write your code so that, when X-1xai-Cost-Toman is absent, it reads the amount from the call's row in the usage report. X-Request-Id is always there.
The cost of a streamed call
- Read
X-Request-Idfrom the response headers; they arrive before the first event. - Read the stream to its end.
- Call
GET /v1/usage?request_id=<that id>. The row is written when the stream has ended and the call is settled, normally within a second of the last event. An emptyusagelist means "not settled yet": ask again after a second or two. - The row's
cost_tomanis the billed amount; if there are several rows, add them up.
import time
import requests
BASE = "https://1xai.ir/v1"
HEADERS = {"Authorization": "Bearer 1xai-..."}
body = {
"model": "gpt-5.5",
"stream": True,
"messages": [{"role": "user", "content": "Hello"}],
}
with requests.post(f"{BASE}/chat/completions", headers=HEADERS, json=body, stream=True) as r:
request_id = r.headers["X-Request-Id"]
for line in r.iter_lines():
pass # use the events here
for _ in range(5):
rows = requests.get(f"{BASE}/usage", headers=HEADERS, params={"request_id": request_id}).json()["usage"]
if rows:
print(request_id, sum(row["cost_toman"] for row in rows))
break
time.sleep(1)The same recipe works for any call, streamed or not. The request_id filter and the CSV export are described under the account API.
1xAi is an independent gateway. It is not affiliated with, endorsed by, or a reseller for OpenAI, Anthropic, Google, DeepSeek, xAI, Moonshot AI, Z.ai, Alibaba Qwen, MiniMax or Tencent Hunyuan. Requests are relayed upstream rather than answered by models of our own, so each provider's own usage policies apply to what their models will and will not do, and their model availability is theirs to change. Current reachability is published on the status page.