Source: https://ailoot.ai/docs/how-it-works/
Canonical: https://ailoot.ai/docs/en/how-it-works/
Language: en

[Overview](https://ailoot.ai/docs/en/) 

# How it works

[Markdown](https://ailoot.ai/docs/en/how-it-works/index.md)

What happens to a request between your application and the model.

Send requests to the Ailoot API as you would send them directly to OpenAI, Anthropic, or Google. Ailoot checks your key and balance, forwards the request to the model, returns its response in the same format, and charges for actual usage.

<em>01</em><strong>Request</strong>Your client sends a request to api.ailoot.ai with an sk-… key

<em>02</em><strong>Validation and reserve</strong>Key, limits, and balance checks. Funds are reserved while the response is prepared.

<em>03</em><strong>Model</strong>The model responds, and the response is returned in your format.

<em>04</em><strong>Charge</strong>One charge based on actual tokens; the unused reserve is released.

## [](https://ailoot.ai/docs/how-it-works/#formats)One key, three formats

The format is determined by the request path, not the model. You can call the same Claude model through OpenAI Chat, OpenAI Responses, or Anthropic Messages; the response uses the format of the path you called.

| Format | Path | Clients that use it |
| --- | --- | --- |
| OpenAI Chat Completions | `/v1/chat/completions` | OpenAI SDK, most chats and editors, n8n, LangChain |
| OpenAI Responses | `/v1/responses` | Codex CLI, OpenAI Agents SDK, newer SDK versions |
| Anthropic Messages | `/v1/messages` | Claude Code, Anthropic SDK, Zed, Cline |
| Gemini | `/v1beta/models/{model}:generateContent` | Gemini CLI, Google GenAI SDK |

## [](https://ailoot.ai/docs/how-it-works/#money)Billing: a reserve and one charge

- Before sending a new text request, Ailoot reserves an estimate of the input and a typical response, taking into account the limit (`max_tokens`) and the exact model’s terms. If the reserve cannot fit within the available balance or key limit, the forwarded response limit can be reduced only for a model and method that actually respect it, and never below 256 tokens or the applicable minimum output length in tokens. Image, video and audio output retain a reserve for the full cost of the result.
- After the response, there is one charge based on actual usage. Any unused reserve is released to your balance immediately.
- If the response costs more than the reserve, the difference is taken from the available balance. Your balance never goes below zero.
- If there is not enough money even for the minimum reserve, the request is not sent. You receive a clear 402 error, and nothing is charged.
- An error that leaves no result is not billed.

For details and a calculation example, see [Reserves and charges](https://ailoot.ai/docs/en/billing/reserve/).

## [](https://ailoot.ai/docs/how-it-works/#errors)Errors with a Request ID

Every response receives a request ID in the `X-Request-ID` header and error message. Errors use the JSON format of the API you called, so SDKs recognize them correctly. If something goes wrong, send the Request ID to [support](https://ailoot.ai/docs/en/support/) so we can find the request within a minute.

401 Unauthorized

```json
{
  "code": "API_KEY_REQUIRED",
  "error": {
    "code": "invalid_api_key",
    "message": "No API key was sent with the request. Nothing was charged. Please check that the full key is sent in the Authorization header as \"Bearer <key>\". Request ID: 3b28d3de-5b02-4d07-9f3c-4b9a7d0e68d6.",
    "param": null,
    "reason": "invalid_api_key",
    "request_id": "3b28d3de-5b02-4d07-9f3c-4b9a7d0e68d6",
    "type": "invalid_request_error"
  },
  "message": "No API key was sent with the request. Nothing was charged. …"
}
```

## [](https://ailoot.ai/docs/how-it-works/#streaming)Streaming and timeouts

Streaming responses (`stream: true`) use Server-Sent Events. Ailoot delivers billed text responses after calculating their cost. With `stream: true` the format is still streaming (SSE), but the text arrives as one block when the model finishes, rather than word by word. If a response takes longer than about 15 seconds, Chat Completions, Responses, and Messages streams first send `: ping` control lines, roughly every 10 seconds, followed by a `: ailoot-charged-usd …` line containing the amount charged and then the data itself. SDKs skip these control lines.

Gemini format has no control lines: the `:streamGenerateContent` response arrives in full after the cost is calculated. Allow extra time in client timeouts for reasoning models; several minutes is normal.

## [](https://ailoot.ai/docs/how-it-works/#headers)Response headers

`X-Request-ID` is included in every response. Ailoot adds the other headers to billed text responses:

| Header | Contents |
| --- | --- |
| `X-Request-ID` | Request ID, which support will ask for |
| `X-Ailoot-Charged-USD` | Amount charged for this request, in dollars |
| `X-Ailoot-Output-Tokens` | Number of billed response tokens |
| `X-Ailoot-Max-Tokens-Capped` | The reduced response limit applied because the balance could not cover the full reserve |
| `X-Ailoot-Notice-Code`, `X-Ailoot-Notice` | An explanation if the response stopped at its length limit |

If the stream has already started with control lines, these details arrive in a comment line before the data rather than in a header.

## [](https://ailoot.ai/docs/how-it-works/#cache)Prompt caching

If the model supports caching, resending a long prefix such as system instructions or documents may cost less. Cache read and write prices are shown on the model’s card in the [catalog](https://ailoot.ai/models/en/). Cache hits are determined by the model developer; Ailoot does not guarantee them.

Still have questions? Send your Request ID and a description — we'll help you troubleshoot.[Contact support](mailto:support@ailoot.ai)

## Ailoot · The company and its project portfolio





Ailoot combines established operating experience, a large client base, stable service and ongoing KPI control.





The company and its project portfolio: millions of customers; monthly sales in the billions.





Ailoot brings that operating experience to API access for AI features in customer products, agents, applications and automations.
