# API

> Every inference route, its request and its response.

## Calling the API

This page lists every route you call models through, generated from the API itself: what each route does, the fields its request takes and what it answers.

The base URL is `https://api.shardio.ai/v1`. Inference routes are also served under `https://api.shardio.ai/openai/v1`, so a tool that expects an OpenAI path works there unchanged. Send your API key as a bearer token, `Authorization: Bearer tsk_live_…`, on authenticated routes. **List prices** and the marketplace model document below are public; the marketplace document is served only at its explicit `/v1/marketplaces/openrouter/models` path.

A refused request answers with an `error` object carrying a `message`, a `type` and a `code`. [Errors](/reference/errors/) explains every code and what to do about it.

## Thinking controls

Chat completions accept a flat `reasoning_effort` or an OpenRouter-style `reasoning` object with `effort` and `enabled`. For example, `"reasoning_effort": "medium"` and `"reasoning": {"effort": "medium"}` choose the same effort on a model that supports it. This is support for those two object fields, not every OpenRouter reasoning control: `reasoning.max_tokens` and `reasoning.exclude` are rejected. The separate top-level `max_tokens` still limits total output; it is not a thinking-only budget.

The accepted choices depend on the model. `none` turns thinking off only where the model allows it. Models with effort levels accept their declared levels; **XHigh** (`xhigh`) is not **Max** (`max`). A toggle-only model has no tiers: any of `minimal`, `low`, `medium`, `high`, `xhigh` or `max` turns thinking on. SuperVL's native `on` is an extension, not an alias for `high`. Mandatory-thinking models refuse off settings.

Use `"reasoning": {"enabled": true}` to enable thinking without selecting an effort. If a level-based model defaults to off, this selects its declared enabled default; otherwise it leaves the enabled default in place. `false` turns thinking off where allowed. Omitting all thinking controls keeps the model's own default.

If you send more than one control, they must agree on the model's resulting setting. An enabled switch can accompany any supported non-off effort, but `enabled: false` conflicts with one. Different native levels conflict; two efforts that both mean On for a toggle-only model agree. The same rule covers `enable_thinking` and the controls in `chat_template_kwargs`. Unsupported or conflicting thinking settings are refused with `reasoning_effort_unsupported` before a credit hold or model dispatch.

## Discovering thinking choices

Read each model's optional `reasoning` object from the public [`/catalog`](https://api.shardio.ai/catalog), or from the authenticated `/v1/models` list. In both responses it sits directly on the model object, not inside `shardio`. The public catalog's separate `supports_reasoning` flag describes separated thinking output, not the available controls. The price sheet at `/v1/catalog/rates` does not include thinking choices.

| Field | Meaning |
|---|---|
| `supported_efforts` | The model's native enabled levels, when it has levels. A toggle-only model omits this field. |
| `default_effort` | The default level, or `none` when a level-based model defaults to off. Omitted for toggle-only models. |
| `default_enabled` | Whether thinking is on by default. |
| `mandatory` | Whether thinking must stay on; if true, do not offer Off. |

An absent `reasoning` object means no declared thinking controls. Use the metadata rather than assuming every model supports the same efforts or starts at Medium. [Models](/use/models/) shows the current choices and defaults.

## Output limits and structured responses

Chat and text completions accept `max_completion_tokens` as an alias of `max_tokens`. Send either name; if both are present, their values must agree, including whether they are `null`. A conflict is refused with 400 before a credit hold.

Chat completions accept `response_format` with `type` set to `text`, `json_object` or `json_schema`. For a JSON Schema, also supply `json_schema` with a `name` and a `schema` object; `description` and `strict` are optional. The schema reaches the engine unchanged.

Constrained formats use only serving recipes that support them, including on a retry or a spill to another recipe. If none can honour the requested format, the request is refused with `response_format_unsupported` before a credit hold. The model list reports `supports_response_format` under `shardio`; the model detail page lists it among supported parameters.

## Token usage in responses

A chat or text completion reports `usage` with `prompt_tokens`, `completion_tokens` and `total_tokens`: the counts you are billed for. A streamed request gets the same object in one final chunk when it sends `"stream_options": {"include_usage": true}`.

`completion_tokens` includes thinking. When the model thought, `usage.completion_tokens_details.reasoning_tokens` gives the thinking share of it. It is already part of `completion_tokens`, not an extra charge, and it equals the thinking tokens shown for the request in your usage history. When the model did not think, `completion_tokens_details` is absent. On a model with a cache-read price, `usage.prompt_tokens_details.cached_tokens` gives the prompt tokens billed at that price.

## Exporting request usage

`GET /v1/usage?period=2026-10&limit=200` returns retained request metadata and costs for a UTC calendar month. `period` defaults to the current month. `limit` is from 1 to 200; pass a returned `next_cursor` as `cursor` to read the next page of the same month.

Any valid inference key may read the whole account's request history, including requests made with sibling or deleted keys. The export never includes another account, prompts or completions. It uses the ordinary request rate limit but does not reserve credit, so an account can export usage at a zero balance.

`detail_from` is the retention boundary. `partial: true` means the requested month starts before that boundary; this is not a complete billing statement. Use the account's statements and invoices for settled billing history. Invalid month, page limit and cursor values return 400 with `invalid_period`, `invalid_limit` and `invalid_cursor`, respectively.

## Marketplace model document

`GET /v1/marketplaces/openrouter/models` returns the [OpenRouter provider model schema](https://openrouter.ai/docs/guides/providers/integration), separate from the OpenAI-shaped `/v1/models`. Its output modality names the API the model actually serves: `text`, `embeddings` or `decisions`. A decision model does not advertise text generation, streaming, sampling parameters or tool calling; its charge is declared on its text input.

## Request ids and per-request costs

Every response to a request that reaches a model carries an `Inference-Id` header with that request's id, such as `req_4mZq8vN2xKpL`. A streamed response sends it before the first chunk. It is the same id your usage export and Activity show, and a chat completion's `id` is the same value with a `chatcmpl-` prefix in place of `req_`.

`POST /v1/billing/costs` with `{"requestIds": ["req_…", …]}` returns `{"requests": [{"requestId": "req_…", "costNanoUsd": 1234000}, …]}`: the cost of each request your account made, in nano-USD (10⁻⁹ USD, so one cent is 10,000,000). Send up to 10,000 ids at a time. An id that is unknown, belongs to another account, is more than two days old or has not settled yet is left out, so ask again later; the same id always answers the same cost. Marketplaces that bill each request they route, such as Hugging Face, call it to learn what to charge. Like the usage export, it uses the ordinary request rate limit and needs no credit.

## Prices in the model list

Each model in `/v1/models` carries `context_length`, the context window in tokens a request may use now (the same figure as `shardio.context_limit`), and `pricing` with `input` and `output` in US dollars per million tokens, the fields marketplaces read. The exact integer prices, in microdollars per million tokens, stay under `shardio` (`price_in_micro_1m`, `price_out_micro_1m`, `price_cache_read_micro_1m`); a model without an input price has no `pricing` object.

## Routes

Every path is also served under `/openai/v1`, as under `/v1`.

### `POST /v1/billing/costs`

**Look up request costs**

The cost of each request this API key's account made, by the id the `Inference-Id` response header named, in nano-USD (10^-9 USD). An id that is unknown, another account's, older than two days, or not settled yet is left out; ask again later. The same id always answers the same cost. Hugging Face Inference Providers calls this to bill the requests it routes. It uses the ordinary request rate limit but needs no credits.

#### Responses

| Status | Content | Description |
|---|---|---|
| 200 | `application/json` | One cost per request id whose cost is known. |

### `GET /v1/catalog/rates`

**List prices**

The public price sheet: every model in the public catalog with its prices per million tokens. Needs no API key; a response may be cached for five minutes.

#### Responses

| Status | Content | Description |
|---|---|---|
| 200 | `application/json` | Each model's prices, context limit and status, with `payout_share`: the host share when every model has the same one, otherwise null. |

### `POST /v1/chat/completions`

**Create a chat completion**

OpenAI-compatible chat completion. Set `stream` to receive the reply as server-sent events.

#### Request body

An OpenAI chat completion request. `ChatCompletionRequest`, `application/json`, required.

| Field | Type | Required | Description |
|---|---|---|---|
| `chat_template_kwargs` | `ChatTemplateOptions` or null | no |  |
| `conversation_id` | string or null | no | `maxLength: 128` |
| `enable_thinking` | boolean or null | no |  |
| `frequency_penalty` | number or null | no | `minimum: -2` `maximum: 2` |
| `max_tokens` | integer or null | no | Maximum total output tokens, including thinking. Also accepted as max_completion_tokens; if both names are sent, their values must agree. `minimum: 1` |
| `messages` | array of `ChatMessage` | yes | `minItems: 1` |
| `model` | string | yes |  |
| `presence_penalty` | number or null | no | `minimum: -2` `maximum: 2` |
| `preserve_thinking` | boolean or null | no |  |
| `reasoning` | `ReasoningOptions` or null | no |  |
| `reasoning_effort` | string or null | no | `minLength: 1` `maxLength: 32` |
| `response_format` | (`TextResponseFormat` or `JsonSchemaResponseFormat`) or null | no |  |
| `seed` | integer or null | no | `minimum: -9223372036854776000` `maximum: 9223372036854776000` |
| `stop` | string or array of string or null | no | `minLength: 1` `maxLength: 256` `minItems: 1` `maxItems: 4` |
| `stream` | boolean | no | `default: false` |
| `stream_options` | `StreamOptions` or null | no |  |
| `temperature` | number or null | no | `minimum: 0` `maximum: 2` |
| `tool_choice` | string or object or null | no |  |
| `tools` | array of object or null | no | `maxItems: 128` |
| `top_p` | number or null | no | `minimum: 0` `maximum: 1` |

#### Responses

| Status | Content | Description |
|---|---|---|
| 200 | `application/json`, `text/event-stream` | A `chat.completion` object. With `stream: true`, a `text/event-stream` of `chat.completion.chunk` events ending with `data: [DONE]`. With `stream_options.include_usage`, a usage chunk comes just before `[DONE]`. Lines starting with `:` keep an idle stream open. A failure after the stream has started arrives as a last event carrying an `error` object, with no `[DONE]`. |

### `POST /v1/completions`

**Create a completion**

OpenAI-compatible text completion of a prompt. Set `stream` to receive the text as server-sent events.

#### Request body

An OpenAI completion request. `CompletionRequest`, `application/json`, required.

| Field | Type | Required | Description |
|---|---|---|---|
| `conversation_id` | string or null | no | `maxLength: 128` |
| `frequency_penalty` | number or null | no | `minimum: -2` `maximum: 2` |
| `max_tokens` | integer or null | no | Maximum total output tokens, including thinking. Also accepted as max_completion_tokens; if both names are sent, their values must agree. `minimum: 1` |
| `model` | string | yes |  |
| `presence_penalty` | number or null | no | `minimum: -2` `maximum: 2` |
| `prompt` | string or array of string or array of object | no | `default: ""` |
| `seed` | integer or null | no | `minimum: -9223372036854776000` `maximum: 9223372036854776000` |
| `stop` | string or array of string or null | no | `minLength: 1` `maxLength: 256` `minItems: 1` `maxItems: 4` |
| `stream` | boolean | no | `default: false` |
| `stream_options` | `StreamOptions` or null | no |  |
| `temperature` | number or null | no | `minimum: 0` `maximum: 2` |
| `top_p` | number or null | no | `minimum: 0` `maximum: 1` |

#### Responses

| Status | Content | Description |
|---|---|---|
| 200 | `application/json`, `text/event-stream` | A `text_completion` object. With `stream: true`, a `text/event-stream` of `text_completion` events ending with `data: [DONE]`. With `stream_options.include_usage`, a usage chunk comes just before `[DONE]`. Lines starting with `:` keep an idle stream open. A failure after the stream has started arrives as a last event carrying an `error` object, with no `[DONE]`. |

### `POST /v1/decisions`

**Ask a decision (OpenAI Decisions)**

OpenAI's Decisions API. It asks the same decision models as the System One route.

#### Request body

An OpenAI Decisions request. The body may be compressed with `Content-Encoding: gzip` or `zstd`. `DecisionsRequest`, `application/json`, required.

| Field | Type | Required | Description |
|---|---|---|---|
| `input` | string or array | yes |  |
| `model` | string | yes |  |
| `questions` | array of (`PredicateQuestion` or `OpenAIChoiceQuestion` or `OpenAIScoreQuestion`) | yes | `minItems: 1` `maxItems: 64` |

#### Responses

| Status | Content | Description |
|---|---|---|
| 200 | `application/json` | The model and one answer per question, in question order, with input token usage. Output is free: `output_tokens` is always 0. |

### `POST /v1/embeddings`

**Create embeddings**

OpenAI-compatible embeddings of one or more texts.

#### Request body

An OpenAI embeddings request. `EmbeddingsRequest`, `application/json`, required.

| Field | Type | Required | Description |
|---|---|---|---|
| `input` | string or array of string | yes |  |
| `model` | string | yes |  |

#### Responses

| Status | Content | Description |
|---|---|---|
| 200 | `application/json` | A list of `embedding` objects, one per input in input order, with the input's token usage. |

### `GET /v1/models`

**List models**

OpenAI-compatible list of the models this API key can call, with Shardio's details under `shardio`: prices, context limit, availability, measured speed and tool support.

#### Responses

| Status | Content | Description |
|---|---|---|
| 200 | `application/json` | A list of `model` objects. |

### `POST /v1/systemone`

**Ask a decision (System One)**

TypeSafe's System One API, so a TypeSafe SDK works with Shardio's base URL alone. It asks the same decision models as the OpenAI-dialect `decisions` route.

#### Request body

A System One request. The body may be compressed with `Content-Encoding: gzip` or `zstd`. `SystemOneRequest`, `application/json`, required.

| Field | Type | Required | Description |
|---|---|---|---|
| `assets` | object or null | no |  |
| `images` | array or null | no |  |
| `model` | string | yes |  |
| `questions` | map of (`NoulQuestion` or `ChoiceQuestion` or `ScoreQuestion`) | yes | `minProperties: 1` `maxProperties: 64` |
| `state` | string or object or array | yes |  |

#### Responses

| Status | Content | Description |
|---|---|---|
| 200 | `application/json` | The model and one answer per question, keyed by question id, with input token usage. Output is free: `output_tokens` is always 0. |

### `GET /v1/usage`

**Export account request usage**

Read retained request metadata and costs for your account with an inference key. Includes requests made with other or deleted keys on the same account, never request or response content. This read uses the ordinary request rate limit but needs no credits. `detail_from` and `partial` describe retained history, not a complete billing statement.

#### Responses

| Status | Content | Description |
|---|---|---|
| 200 | `application/json` | A page of request metadata, its next cursor and retention coverage. |

## Schemas

### `ChatMessage`

| Field | Type | Required | Description |
|---|---|---|---|
| `content` | string or array of object | no | `default: ""` |
| `role` | "system" \| "assistant" \| "user" \| "tool" \| "developer" | yes |  |
| `tool_call_id` | string or null | no |  |
| `tool_calls` | array of object or null | no |  |

### `ChatTemplateOptions`

| Field | Type | Required | Description |
|---|---|---|---|
| `enable_thinking` | boolean or null | no |  |
| `preserve_thinking` | boolean or null | no |  |
| `reasoning_effort` | string or null | no | `minLength: 1` `maxLength: 32` |

### `ChoiceOption`

| Field | Type | Required | Description |
|---|---|---|---|
| `description` | string or null | no |  |
| `value` | string or boolean | yes |  |

### `ChoiceQuestion`

| Field | Type | Required | Description |
|---|---|---|---|
| `criteria` | map of (string or object or array or null) | yes | `minProperties: 1` `maxProperties: 255` |
| `instructions` | string or object or array or null | no |  |
| `type` | "choice" | yes |  |

### `JsonSchemaResponseFormat`

| Field | Type | Required | Description |
|---|---|---|---|
| `json_schema` | `ResponseJsonSchema` | yes |  |
| `type` | "json_schema" | yes |  |

### `Level`

| Field | Type | Required | Description |
|---|---|---|---|
| `description` | string or null | no |  |
| `label` | string | yes |  |

### `NoulCriteria`

| Field | Type | Required | Description |
|---|---|---|---|
| `false` | string or object or array or null | no |  |
| `true` | string or object or array or null | no |  |

### `NoulQuestion`

| Field | Type | Required | Description |
|---|---|---|---|
| `criteria` | `NoulCriteria` or null | no |  |
| `instructions` | string or object or array or null | no |  |
| `type` | "noul" | yes |  |

### `OpenAIChoiceQuestion`

| Field | Type | Required | Description |
|---|---|---|---|
| `choices` | array of `ChoiceOption` | yes | `minItems: 2` `maxItems: 255` |
| `instructions` | string | yes |  |
| `name` | string or null | no |  |
| `type` | "choice" | yes |  |

### `OpenAIScoreQuestion`

| Field | Type | Required | Description |
|---|---|---|---|
| `instructions` | string | yes |  |
| `levels` | array of `Level` | yes | `minItems: 1` `maxItems: 10` |
| `name` | string or null | no |  |
| `type` | "score" | yes |  |

### `PredicateQuestion`

| Field | Type | Required | Description |
|---|---|---|---|
| `instructions` | string | yes |  |
| `name` | string or null | no |  |
| `type` | "predicate" | yes |  |

### `ReasoningOptions`

| Field | Type | Required | Description |
|---|---|---|---|
| `effort` | string or null | no | `minLength: 1` `maxLength: 32` |
| `enabled` | boolean or null | no |  |

### `ResponseJsonSchema`

| Field | Type | Required | Description |
|---|---|---|---|
| `description` | string or null | no |  |
| `name` | string | yes | `minLength: 1` `maxLength: 64` |
| `schema` | object | yes |  |
| `strict` | boolean or null | no |  |

### `ScoreQuestion`

| Field | Type | Required | Description |
|---|---|---|---|
| `criteria` | array of (string or object or array) | yes | `minItems: 1` `maxItems: 10` |
| `instructions` | string or object or array or null | no |  |
| `type` | "score" | yes |  |

### `StreamOptions`

| Field | Type | Required | Description |
|---|---|---|---|
| `include_usage` | boolean | no | `default: false` |

### `TextResponseFormat`

| Field | Type | Required | Description |
|---|---|---|---|
| `type` | "text" \| "json_object" | yes |  |
