IN ENGLISH · API DOCS

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:

[01]REQUEST ID AND COST

The request id: X-Request-Id

The headers of a non-streamed answerhttp
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), /anthropic and /gemini carries exactly one X-Request-Id, whether the request was served or refused: a 401, 402, 403, 404 or 429, an error relayed from the model's vendor, and a 502 or 504 of 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 own X-Request-Id is not forwarded.
  • On /anthropic, when Anthropic sent a Request-Id header, the answer carries it too, with the same 1xAi id. So _request_id in the Anthropic and OpenAI SDKs is the id you give support.
  • It is the same id as: the request_id of the call's row in GET /v1/usage and the value its request_id= filter takes, the request_id column of the CSV export, the request id the dashboard's call log shows on an opened row (and finds in its search box), and the reference of the call's charge in GET /v1/wallet/transactions (account API).
  • The X-1xai-Request-Id header, with the same value, is still sent.
  • The id of a POST /v1/realtime/client_secret answer names that request only; the calls of a voice session have usage rows with ids of their own (rt_…) (realtime voice).
Reading the headers with the OpenAI SDKpython
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()
[02]REQUEST ID AND COST

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).

Routes whose answers carry the cost header
RouteWhen
POST /v1/chat/completions, /v1/completions, /v1/responses, /v1/embeddingsWhen:A 2xx answer, not streamed
POST /v1/messages, /anthropic/v1/messagesWhen:A 2xx answer, not streamed
POST /gemini/v1beta/models/{model}:generateContentWhen:A 2xx answer
POST /v1/images/generations, /v1/images/edits, /v1/images/variationsWhen:A 2xx answer
POST /v1/audio/transcriptions, /v1/audio/translations, /v1/audio/speechWhen: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 400 or above carries it, not even 0: 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 :predictLongRunning and /interactions, Anthropic message batches, OpenAI batches (POST /v1/batches) and realtime voice. Their cost is in their rows of GET /v1/usage.
  • Free routes do not carry it: /v1/moderations, token counts, /v1/models, the account API and the /v1/files routes.
  • 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.

[03]REQUEST ID AND COST

The cost of a streamed call

  1. Read X-Request-Id from the response headers; they arrive before the first event.
  2. Read the stream to its end.
  3. 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 empty usage list means "not settled yet": ask again after a second or two.
  4. The row's cost_toman is the billed amount; if there are several rows, add them up.
Pythonpython
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.