Source: https://antarya.ai/docs # Antarya API > Build with the Antarya API: make a key, send a first request and read the reference. ## Start here Antarya replies to a conversation you send over a plain web API. Pick where you want to begin. - [Quickstart](https://antarya.ai/docs/quickstart.md): Make a key and send your first request. - [API reference](https://antarya.ai/docs/api.md): Every endpoint, with its parameters and replies. - [CLI](https://antarya.ai/docs/cli.md): Ask from your terminal. For agents and tools, [/llms.txt](https://antarya.ai/llms.txt) lists every docs page, [/llms-full.txt](https://antarya.ai/llms-full.txt) holds them all in one file, and each page has a Markdown copy at its address plus `.md`, such as `https://antarya.ai/docs/quickstart.md`. --- Source: https://antarya.ai/docs/quickstart # Quickstart > Make a key, set it in your shell and send your first request to Antarya. ## Send your first request Three steps. You need an Antarya account and a terminal. 1. Create a key. Open Keys in your account and choose Create key. Copy it now; it is shown once. 2. Set it as `ANTARYA_API_KEY` in your shell: `export ANTARYA_API_KEY=ak-...` on macOS and Linux, or `$env:ANTARYA_API_KEY = "ak-..."` in PowerShell. 3. Send a request. Pick your language below. Each sample asks one question and prints the reply. For Python, run `pip install antarya` first; for TypeScript, `npm install antarya`; for the CLI, see the [CLI page](https://antarya.ai/docs/cli.md). ```bash curl https://antarya.ai/v1/chat \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "messages": [ {"role": "user", "content": "Summarise the termination clause of this contract."} ] }' ``` ```python from antarya import Antarya client = Antarya() # reads ANTARYA_API_KEY reply = client.chat.create( messages=[{"role": "user", "content": "Summarise this contract's termination clause."}], ) print(reply.content[0].text) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); // reads ANTARYA_API_KEY const reply = await client.chat.create({ messages: [{ role: "user", content: "Summarise this contract's termination clause." }], }); console.log(reply.content[0].text); ``` ```bash antarya "Summarise this contract's termination clause." ``` Output: ``` { "id": "req_01", "content": [ {"type": "text", "text": "Either side can end the agreement with written notice..."} ], "stop_reason": "end_turn", "usage": {"input_tokens": 18, "output_tokens": 64} } ``` ## What came back The reply is in `content`. `stop_reason` says why the reply ended, and `usage` gives the tokens you were billed for. To continue the conversation, send the whole `messages` list again with the reply added as an `assistant` message. To ask about a document or a picture, put a file or an image in the message next to the text. See [files and images](https://antarya.ai/docs/guides/files-and-images.md). ## Next steps - [Models](https://antarya.ai/docs/models.md): The id, the limits and how aliases work. - [CLI](https://antarya.ai/docs/cli.md): Install it and ask from your terminal. - [Python SDK](https://antarya.ai/docs/sdk/python.md): The same request from Python. --- Source: https://antarya.ai/docs/models # Models > The Antarya model, its limits and how ids and aliases work. ## Available models One model today. | Id | Maximum output | Inputs | Knowledge cutoff | |---|---|---|---| | `antarya` | 2,048 tokens | Text, images and files | To be announced | ## Capabilities | Capability | Today | |---|---| | Conversations | On | | Images | On | | Files | On | | Streaming | On | | Thinking | On | | System instructions | Not yet | | Tools | Not yet | | Structured output | Not yet | | Artifacts | Not yet | The model object's `capabilities` turns each flag true when it is on. ## Ids and aliases Send the id in the `model` field of a request. Leave it out and Antarya uses `antarya`. The one id today is `antarya`. Any other id gets a 404 `not_found`. `GET /v1/models` lists the ids your key can use, and `GET /v1/models/{id}` describes one. ## Next steps - [Quickstart](https://antarya.ai/docs/quickstart.md): Send a first request. - [API reference](https://antarya.ai/docs/api.md): Every endpoint, with its parameters and replies. --- Source: https://antarya.ai/docs/cli # CLI > Install the Antarya command line, sign in and ask from your terminal. ## Install On macOS and Linux: ```bash curl -fsSL https://antarya.ai/install.sh | sh ``` On Windows, in PowerShell: ```bash irm https://antarya.ai/install.ps1 | iex ``` ## Sign in `antarya login` opens your browser and saves a key on this machine. To use a key you made yourself, set `ANTARYA_API_KEY` instead. ```bash antarya login ``` ## Ask a question Put the question in quotes. The reply prints and the command ends. ```bash antarya "Draft a reply that declines the meeting." ``` Pipe a file in and ask about it: ```bash cat agreement.txt | antarya "Summarise the termination clause." ``` ## Options - `--system` (text, optional): Instructions that apply to the whole conversation, for example "Answer in plain English." - `--json` (flag, optional): Print the full response as JSON instead of only the reply text. - `--file` (path, optional): Attach a file to the question. Repeat the option to attach more than one. ```bash antarya --file agreement.pdf --system "Answer in plain English." "What can I end this early for?" ``` ## A conversation `antarya chat` opens a conversation that keeps its history in a [session](https://antarya.ai/docs/guides/sessions.md) until you leave it with Ctrl+D. Leaving deletes the session. ```bash antarya chat ``` ## Config and uninstall The CLI keeps its settings in `~/.config/antarya/config.toml` on macOS and Linux, and in `%APPDATA%\antarya\config.toml` on Windows. Delete that file to sign out. To uninstall, run `antarya uninstall`. It removes the program and the config file. ## Next steps - [Quickstart](https://antarya.ai/docs/quickstart.md): Make a key and send your first request. - [Python SDK](https://antarya.ai/docs/sdk/python.md): Use Antarya from Python. - [TypeScript SDK](https://antarya.ai/docs/sdk/typescript.md): Use Antarya from TypeScript. --- Source: https://antarya.ai/docs/sdk/python # Python SDK > Install the antarya package and send requests from Python. ## Install ```python pip install antarya ``` ## Client The client reads `ANTARYA_API_KEY`. Pass `api_key="ak-..."` to use a different key. ```python from antarya import Antarya client = Antarya() reply = client.chat.create( messages=[{"role": "user", "content": "Summarise this contract's termination clause."}], ) print(reply.content[0].text) ``` ## Streaming Call `client.chat.stream` (or `client.chat.create` with `stream=True`) and read the events as they arrive. ```python with client.chat.stream( messages=[{"role": "user", "content": "Draft a reply that declines the meeting."}], ) as stream: for text in stream.text: print(text, end="") ``` ## Files and images A message can carry files and images next to its text. Upload a file once and refer to it by its id in any message, or send a file or an image inside the request, where it is read for that request only and not stored. Files can be PDF, Word, Excel, text, Markdown, CSV or JSON, up to 10 MB each. Images can be PNG, JPEG or WebP, up to 10 MB each and 20 a request. The [files and images guide](https://antarya.ai/docs/guides/files-and-images.md) has more. ```python import base64 # Upload once, then refer to the file by id. file = client.files.create(file="agreement.pdf") reply = client.chat.create( messages=[{ "role": "user", "content": [ {"type": "file", "file_id": file.id}, {"type": "text", "text": "Summarise the termination clause in this agreement."}, ], }], ) # Or send the file inside the request, without storing it. with open("agreement.pdf", "rb") as f: data = base64.b64encode(f.read()).decode() reply = client.chat.create( messages=[{ "role": "user", "content": [ {"type": "file", "source": {"type": "base64", "filename": "agreement.pdf", "media_type": "application/pdf", "data": data}}, {"type": "text", "text": "Summarise the termination clause in this agreement."}, ], }], ) # An image goes the same way. with open("signature-page.png", "rb") as f: image = base64.b64encode(f.read()).decode() reply = client.chat.create( messages=[{ "role": "user", "content": [ {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": image}}, {"type": "text", "text": "Who signed this page?"}, ], }], ) ``` ## Sessions A session keeps the conversation on Antarya's side, so you send only the new turn. See the [sessions guide](https://antarya.ai/docs/guides/sessions.md) for how it works and the [sessions reference](https://antarya.ai/docs/api/sessions.md) for its limits. The package has these calls from version 0.1.0. ```python session = client.sessions.create(metadata={"matter": "acme-msa"}) reply = client.chat.create( session_id=session.id, messages=[{"role": "user", "content": "Summarise the termination clause."}], ) page = client.sessions.list(limit=20) if page.has_more: page = client.sessions.list(limit=20, after=page.data[-1].id) saved = client.sessions.get(session.id) print(saved.messages) client.sessions.delete(session.id) ``` `create` returns `id`, `object`, `created_at`, `updated_at` and `metadata`, with ids like `sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31`. `get` adds `messages`. `list` returns `object`, `data` and `has_more`, and `client.files.list` pages the same way. `delete` returns `id` and `deleted`. ## Errors and retries A failed request raises `antarya.APIError`. It carries `status`, `type`, `message` and `request_id`. The client retries 429 and 5xx replies twice, with a short wait between tries. Change that with `Antarya(max_retries=4)`. ```python import antarya try: client.chat.create(messages=[{"role": "user", "content": "Hello"}]) except antarya.APIError as e: print(e.status, e.type, e.request_id) ``` ## Async ```python import asyncio from antarya import AsyncAntarya client = AsyncAntarya() async def main(): reply = await client.chat.create( messages=[{"role": "user", "content": "Summarise this contract's termination clause."}], ) print(reply.content[0].text) asyncio.run(main()) ``` ## Next steps - [TypeScript SDK](https://antarya.ai/docs/sdk/typescript.md): The same set for TypeScript. - [CLI](https://antarya.ai/docs/cli.md): Ask from your terminal. - [Quickstart](https://antarya.ai/docs/quickstart.md): Make a key and send your first request. --- Source: https://antarya.ai/docs/sdk/typescript # TypeScript SDK > Install the antarya package from npm and send requests from TypeScript. ## Install ```typescript npm install antarya ``` ## Client The client reads `ANTARYA_API_KEY`. Pass `{ apiKey: "ak-..." }` to use a different key. ```typescript import Antarya from "antarya"; const client = new Antarya(); const reply = await client.chat.create({ messages: [{ role: "user", content: "Summarise this contract's termination clause." }], }); console.log(reply.content[0].text); ``` ## Streaming Set `stream: true` and loop over the events as they arrive. ```typescript const stream = await client.chat.create({ messages: [{ role: "user", content: "Draft a reply that declines the meeting." }], stream: true, }); for await (const event of stream) { if (event.type === "content.delta" && typeof event.text === "string") process.stdout.write(event.text); } ``` ## Files and images A message can carry files and images next to its text. Upload a file once and refer to it by its id in any message, or send a file or an image inside the request, where it is read for that request only and not stored. Files can be PDF, Word, Excel, text, Markdown, CSV or JSON, up to 10 MB each. Images can be PNG, JPEG or WebP, up to 10 MB each and 20 a request. The [files and images guide](https://antarya.ai/docs/guides/files-and-images.md) has more. ```typescript import fs from "node:fs"; // Upload once, then refer to the file by id. const file = await client.files.create({ file: fs.createReadStream("agreement.pdf") }); await client.chat.create({ messages: [{ role: "user", content: [ { type: "file", file_id: file.id }, { type: "text", text: "Summarise the termination clause in this agreement." }, ], }], }); // Or send the file inside the request, without storing it. const data = fs.readFileSync("agreement.pdf").toString("base64"); await client.chat.create({ messages: [{ role: "user", content: [ { type: "file", source: { type: "base64", filename: "agreement.pdf", media_type: "application/pdf", data } }, { type: "text", text: "Summarise the termination clause in this agreement." }, ], }], }); // An image goes the same way. const image = fs.readFileSync("signature-page.png").toString("base64"); await client.chat.create({ messages: [{ role: "user", content: [ { type: "image", source: { type: "base64", media_type: "image/png", data: image } }, { type: "text", text: "Who signed this page?" }, ], }], }); ``` ## Sessions A session keeps the conversation on Antarya's side, so you send only the new turn. See the [sessions guide](https://antarya.ai/docs/guides/sessions.md) for how it works and the [sessions reference](https://antarya.ai/docs/api/sessions.md) for its limits. Versions 0.1.2 and later of the package have these methods. ```typescript const session = await client.sessions.create({ metadata: { matter: "acme-msa" } }); const reply = await client.chat.create({ session_id: session.id, messages: [{ role: "user", content: "Summarise the termination clause." }], }); let page = await client.sessions.list({ limit: 20 }); if (page.has_more) page = await client.sessions.list({ limit: 20, after: page.data.at(-1)!.id }); const saved = await client.sessions.get(session.id); console.log(saved.messages); await client.sessions.delete(session.id); ``` `create` returns `{ id, object: "session", created_at, updated_at, metadata }`, with ids like `sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31`. `get` returns the same fields plus `messages`. `list` returns `{ object: "list", data, has_more }`, and `client.files.list` pages the same way. `delete` returns `{ id, deleted: true }`. ## Errors and retries A failed request throws `Antarya.APIError`. It carries `status`, `type`, `message` and `requestId`. The client retries 429 and 5xx replies twice, with a short wait between tries. Change that with `new Antarya({ maxRetries: 4 })`. ```typescript try { await client.chat.create({ messages: [{ role: "user", content: "Hello" }] }); } catch (e) { if (e instanceof Antarya.APIError) console.log(e.status, e.type, e.requestId); else throw e; } ``` ## Async Every method returns a promise, so there is no separate async client. Run requests side by side with `Promise.all`. ```typescript const questions = ["Summarise the termination clause.", "Draft a reply that declines the meeting."]; const replies = await Promise.all( questions.map((q) => client.chat.create({ messages: [{ role: "user", content: q }] })), ); ``` ## Next steps - [Python SDK](https://antarya.ai/docs/sdk/python.md): The same set for Python. - [CLI](https://antarya.ai/docs/cli.md): Ask from your terminal. - [Quickstart](https://antarya.ai/docs/quickstart.md): Make a key and send your first request. --- Source: https://antarya.ai/docs/guides/conversations # Conversations > Keep a conversation going by sending its history with each request. ## What it is for Antarya does not remember earlier requests. A conversation is the `messages` list you send: every turn so far, oldest first. To continue, add the reply as an `assistant` message, add the next question as a `user` message and send the whole list again. ## Send the history ```bash curl https://antarya.ai/v1/chat \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "messages": [ {"role": "user", "content": "Summarise this contract'"'"'s termination clause."}, {"role": "assistant", "content": "Either side can end the agreement with 30 days of written notice."}, {"role": "user", "content": "Draft a reply that accepts those terms."} ] }' ``` ```python from antarya import Antarya client = Antarya() messages = [{"role": "user", "content": "Summarise this contract's termination clause."}] reply = client.chat.create(messages=messages) messages.append({"role": "assistant", "content": reply.content[0].text}) messages.append({"role": "user", "content": "Draft a reply that accepts those terms."}) reply = client.chat.create(messages=messages) print(reply.content[0].text) ``` ```typescript import Antarya, { type Message } from "antarya"; const client = new Antarya(); const messages: Message[] = [{ role: "user", content: "Summarise this contract's termination clause." }]; let reply = await client.chat.create({ messages }); messages.push({ role: "assistant", content: reply.content[0]?.text ?? "" }); messages.push({ role: "user", content: "Draft a reply that accepts those terms." }); reply = await client.chat.create({ messages }); console.log(reply.content[0].text); ``` ```bash antarya chat ``` Output: ``` { "id": "req_02", "content": [ {"type": "text", "text": "Thank you for the summary. We accept the notice terms as written..."} ], "stop_reason": "end_turn", "usage": {"input_tokens": 71, "output_tokens": 48} } ``` `antarya chat` keeps the history for you until you leave it with Ctrl+D. ## Parameters - `messages` (array, required): The conversation so far, oldest first. Each turn is sent again on every request. - `messages.role` (text, required): "user" for your turns, "assistant" for replies you are passing back, "tool" for tool results. - `messages.content` (text or array, required): The turn as plain text, or a list of parts when it holds more than text. - `model` (text, optional): Which model answers. Leave it out to use the current default. ## Limits Every turn you send counts as input tokens, so a long conversation costs more with each request. Count a conversation before you send it with [Counting tokens](https://antarya.ai/docs/guides/counting-tokens.md). To keep a conversation for you, use a stored session (see [sessions](https://antarya.ai/docs/guides/sessions.md)) and pass its `session_id`. ## Next steps - [System instructions](https://antarya.ai/docs/guides/system-instructions.md): Set how Antarya answers for the whole conversation. - [Streaming](https://antarya.ai/docs/guides/streaming.md): Show the reply as it is written. - [Counting tokens](https://antarya.ai/docs/guides/counting-tokens.md): Know the size of a conversation before you send it. - [Sessions](https://antarya.ai/docs/guides/sessions.md): Let Antarya keep the history for you. --- Source: https://antarya.ai/docs/guides/sessions # Sessions > Keep a conversation on Antarya's side and send only the new turn. ## What it is for By default Antarya is stateless: each request carries the whole conversation, as the [conversations guide](https://antarya.ai/docs/guides/conversations.md) shows. A session keeps the turns for you. You create it once, pass its id as `session_id` and send only the new message. Use one when you do not want to hold and resend the history yourself. ## Create a session and send a turn ```bash curl https://antarya.ai/v1/sessions \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{}' # use the id from the create reply as session_id curl https://antarya.ai/v1/chat \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "session_id": "sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31", "messages": [{"role": "user", "content": "Summarise the termination clause."}] }' ``` ```python from antarya import Antarya client = Antarya() session = client.sessions.create() reply = client.chat.create( session_id=session.id, messages=[{"role": "user", "content": "Summarise the termination clause."}], ) print(reply.content[0].text) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const session = await client.sessions.create(); const reply = await client.chat.create({ session_id: session.id, messages: [{ role: "user", content: "Summarise the termination clause." }], }); console.log(reply.content[0].text); ``` Output: ``` { "id": "req_04", "content": [ {"type": "text", "text": "Either side can end the agreement with 30 days of written notice."} ], "stop_reason": "end_turn", "usage": {"input_tokens": 18, "output_tokens": 16} } ``` ## Continue it Send the next turn with the same `session_id`. The saved turns go before your `messages`, so you send only what is new. ```python reply = client.chat.create( session_id=session.id, messages=[{"role": "user", "content": "Draft a reply that accepts those terms."}], ) ``` ```typescript const next = await client.chat.create({ session_id: session.id, messages: [{ role: "user", content: "Draft a reply that accepts those terms." }], }); ``` When a request succeeds, the new turns and the reply are saved. A failed or refused request saves nothing, so you can send it again. ## List, read and delete ```bash curl https://antarya.ai/v1/sessions \ -H "Authorization: Bearer $ANTARYA_API_KEY" ``` ```python page = client.sessions.list(limit=20) for s in page.data: print(s.id) if page.has_more: page = client.sessions.list(limit=20, after=page.data[-1].id) saved = client.sessions.get(session.id) print(saved.messages) client.sessions.delete(session.id) ``` ```typescript let page = await client.sessions.list({ limit: 20 }); for (const s of page.data) console.log(s.id); if (page.has_more) page = await client.sessions.list({ limit: 20, after: page.data.at(-1)!.id }); const saved = await client.sessions.get(session.id); console.log(saved.messages); await client.sessions.delete(session.id); ``` `has_more` is true when another page exists. Deleting a session removes the turns stored in it. ## Limits - An account holds at most 1,000 sessions, and every key on the account can use them. - Paging, the session object and the other fields are in the [sessions reference](https://antarya.ai/docs/api/sessions.md). ## Next steps - [Sessions reference](https://antarya.ai/docs/api/sessions.md): The four endpoints, the object and paging. - [Conversations](https://antarya.ai/docs/guides/conversations.md): Keep the history yourself instead. - [Streaming](https://antarya.ai/docs/guides/streaming.md): Show the reply as it is written. --- Source: https://antarya.ai/docs/guides/streaming # Streaming > Receive a reply as it is written, as server-sent events. ## What it is for Without streaming, you wait for the whole reply. With `stream` set to true, the reply arrives in pieces as it is written, so you can show text straight away. ## Stream a reply ```bash curl https://antarya.ai/v1/chat \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -N \ -d '{ "stream": true, "messages": [ {"role": "user", "content": "Draft a reply that declines the meeting."} ] }' ``` ```python from antarya import Antarya client = Antarya() with client.chat.stream( messages=[{"role": "user", "content": "Draft a reply that declines the meeting."}], ) as stream: for text in stream.text: print(text, end="") ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const stream = await client.chat.create({ messages: [{ role: "user", content: "Draft a reply that declines the meeting." }], stream: true, }); for await (const event of stream) { if (event.type === "content.delta" && typeof event.text === "string") process.stdout.write(event.text); } ``` Output: ``` event: reply.start data: {"id": "req_03", "model": "antarya"} event: content.delta data: {"index": 0, "type": "text", "text": "Thank you for the invitation. "} event: content.delta data: {"index": 0, "type": "text", "text": "I am unable to join on Thursday."} event: reply.done data: {"stop_reason": "end_turn", "usage": {"input_tokens": 14, "output_tokens": 19}} ``` ## Events The response is a stream of server-sent events. Each has an `event:` name and a `data:` line of JSON. | Event | When it arrives | Data | |---|---|---| | `reply.start` | Once, first. | `id` and `model`. | | `thinking` | Only when `include_thinking` is true, between `reply.start` and the first `content.delta`. | `step`, `stage` and `summary`. | | `content.delta` | Many times. | `index`, `type` and the next piece of `text`. | | `reply.done` | Once, last. | `stop_reason` and `usage`. | | `error` | If the request fails after the stream has begun. | The same `error` object as other failures, with a `request_id`. | While Antarya works, the server sends a `: ping` comment line every 15 seconds so the connection stays open. Ignore it. A `thinking` event is a short note on progress: `stage` is a short label and `summary` says what that step did. Thinking notes are not counted as output tokens. Join the `text` of every `content.delta` in order to get the full reply. Treat `reply.done` as the end: `usage` is final there. A request that fails before the stream begins returns an ordinary error status instead of an `error` event. ## Parameters - `stream` (boolean, optional): Set to true to receive server-sent events instead of one JSON body. The default is false. - `include_thinking` (boolean, optional): Set to true to receive `thinking` events before the first `content.delta`. The default is false. - `messages` (array, required): The conversation, as in any chat request. ## Next steps - [Errors](https://antarya.ai/docs/api.md): What each failure looks like and how to handle it. - [Python SDK](https://antarya.ai/docs/sdk/python.md): The stream helper and its options. - [TypeScript SDK](https://antarya.ai/docs/sdk/typescript.md): Loop over events as they arrive. --- Source: https://antarya.ai/docs/guides/system-instructions # System instructions > Tell Antarya how to answer for a whole conversation. This is not available on this model yet. The model object's `capabilities.system` turns true when it is. ## What it is for A system instruction sets the way Antarya answers for every turn: the role she plays, the tone, the format. Put it in `system`, not in a user message, so it applies without being repeated in the conversation. ## Add an instruction ```bash curl https://antarya.ai/v1/chat \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "system": "You are a careful contracts assistant. Answer in plain English and keep it under 120 words.", "messages": [ {"role": "user", "content": "Summarise this contract'"'"'s termination clause."} ] }' ``` ```python from antarya import Antarya client = Antarya() reply = client.chat.create( system="You are a careful contracts assistant. Answer in plain English and keep it under 120 words.", messages=[{"role": "user", "content": "Summarise this contract's termination clause."}], ) print(reply.content[0].text) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const reply = await client.chat.create({ system: "You are a careful contracts assistant. Answer in plain English and keep it under 120 words.", messages: [{ role: "user", content: "Summarise this contract's termination clause." }], }); console.log(reply.content[0].text); ``` ```bash antarya --system "You are a careful contracts assistant. Answer in plain English and keep it under 120 words." "Summarise this contract's termination clause." ``` Output: ``` { "id": "req_04", "content": [ {"type": "text", "text": "Either side can end the agreement by giving 30 days of written notice..."} ], "stop_reason": "end_turn", "usage": {"input_tokens": 41, "output_tokens": 52} } ``` ## Writing a good instruction State what you want, not what you fear. "Answer in plain English" works better than a list of things to avoid. Give the role once, then the format. If the answer feeds another program, say so and ask for the exact shape; for strict shapes use [Structured output](https://antarya.ai/docs/guides/structured-output.md) instead. ## Parameters - `system` (text, optional): Instructions that apply to the whole conversation. Send it again with every request, since Antarya keeps nothing between requests. - `messages` (array, required): The conversation, as in any chat request. ## Next steps - [Structured output](https://antarya.ai/docs/guides/structured-output.md): Get replies in a JSON shape you define. - [Conversations](https://antarya.ai/docs/guides/conversations.md): Pass history from turn to turn. - [CLI](https://antarya.ai/docs/cli.md): Use --system from your terminal. --- Source: https://antarya.ai/docs/guides/structured-output # Structured output > Get replies as JSON that matches a schema you define. This is not available on this model yet. The model object's `capabilities.structured_output` turns true when it is. ## What it is for When a program reads the reply, free text is hard to use. Give `response_format` a JSON schema and the reply comes back as JSON in that shape. ## Ask for a schema ```bash curl https://antarya.ai/v1/chat \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "messages": [ {"role": "user", "content": "Summarise this contract'"'"'s termination clause."} ], "response_format": { "type": "json_schema", "schema": { "type": "object", "properties": { "notice_period": {"type": "string"}, "who_can_end_it": {"type": "string"}, "summary": {"type": "string"} }, "required": ["notice_period", "who_can_end_it", "summary"] } } }' ``` ```python import json from antarya import Antarya client = Antarya() reply = client.chat.create( messages=[{"role": "user", "content": "Summarise this contract's termination clause."}], response_format={ "type": "json_schema", "schema": { "type": "object", "properties": { "notice_period": {"type": "string"}, "who_can_end_it": {"type": "string"}, "summary": {"type": "string"}, }, "required": ["notice_period", "who_can_end_it", "summary"], }, }, ) clause = json.loads(reply.content[0].text) print(clause["notice_period"]) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const reply = await client.chat.create({ messages: [{ role: "user", content: "Summarise this contract's termination clause." }], response_format: { type: "json_schema", schema: { type: "object", properties: { notice_period: { type: "string" }, who_can_end_it: { type: "string" }, summary: { type: "string" }, }, required: ["notice_period", "who_can_end_it", "summary"], }, }, }); const clause = JSON.parse(reply.content[0]?.text ?? "{}"); console.log(clause.notice_period); ``` Output: ``` { "id": "req_05", "content": [ {"type": "text", "text": "{\"notice_period\": \"30 days\", \"who_can_end_it\": \"Either party\", \"summary\": \"Either side can end the agreement with written notice.\"}"} ], "stop_reason": "end_turn", "usage": {"input_tokens": 96, "output_tokens": 44} } ``` The JSON is the text of the first content part. Parse it as you would any JSON string. ## Parameters - `response_format` (object, optional): Asks for the reply as JSON in a shape you give. - `response_format.type` (text, required): Always "json_schema". - `response_format.schema` (object, required): A JSON schema for the reply. ## Limits If the reply stops early because it reached `max_output_tokens`, the JSON may be cut off. Read `stop_reason` before you parse: a reply that ended with `max_output_tokens` is not complete JSON. | Limit | Value | |---|---| | Supported schema keywords | type, properties, required, items, enum, description, additionalProperties | ## Next steps - [Tool use](https://antarya.ai/docs/guides/tool-use.md): Let Antarya call your functions. - [System instructions](https://antarya.ai/docs/guides/system-instructions.md): Set the tone and role for every reply. - [Python SDK](https://antarya.ai/docs/sdk/python.md): Parse replies in Python. --- Source: https://antarya.ai/docs/guides/tool-use # Tool use > Let Antarya ask your code to run a function and use the result. This is not available on this model yet. The model object's `capabilities.tools` turns true when it is. ## What it is for Antarya cannot look up your calendar or open your database. With tools, you describe a function; when she needs it, the reply contains a request to call it. You run the function and send the result back, and she finishes the answer. ## The loop 1. Send the question with `tools`, a list of functions you describe. 2. If the reply has a `tool_call` part, run that function with its `input`. 3. Send the conversation again, with the reply added and a `tool` message holding the result. 4. Repeat until `stop_reason` is `end_turn`. ```bash curl https://antarya.ai/v1/chat \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "messages": [ {"role": "user", "content": "Draft a reply that declines the meeting."} ], "tools": [ { "name": "get_free_slots", "description": "Return the free calendar slots for a given week.", "input_schema": { "type": "object", "properties": {"week": {"type": "string"}}, "required": ["week"] } } ], "tool_choice": {"type": "auto"} }' ``` ```python from antarya import Antarya client = Antarya() tools = [{ "name": "get_free_slots", "description": "Return the free calendar slots for a given week.", "input_schema": { "type": "object", "properties": {"week": {"type": "string"}}, "required": ["week"], }, }] messages = [{"role": "user", "content": "Draft a reply that declines the meeting."}] reply = client.chat.create(messages=messages, tools=tools, tool_choice={"type": "auto"}) for part in reply.content: if part.type == "tool_call": slots = "Tuesday 10:00, Wednesday 14:00" # run your own function here messages.append({"role": "assistant", "content": reply.content}) messages.append({ "role": "tool", "content": [{"type": "tool_result", "tool_call_id": part.id, "content": slots}], }) reply = client.chat.create(messages=messages, tools=tools) print(reply.content[0].text) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const tools = [{ name: "get_free_slots", description: "Return the free calendar slots for a given week.", input_schema: { type: "object", properties: { week: { type: "string" } }, required: ["week"], }, }]; const messages: any[] = [{ role: "user", content: "Draft a reply that declines the meeting." }]; let reply = await client.chat.create({ messages, tools, tool_choice: { type: "auto" } }); for (const part of reply.content) { if (part.type === "tool_call") { const slots = "Tuesday 10:00, Wednesday 14:00"; // run your own function here messages.push({ role: "assistant", content: reply.content }); messages.push({ role: "tool", content: [{ type: "tool_result", tool_call_id: part.id, content: slots }], }); reply = await client.chat.create({ messages, tools }); } } console.log(reply.content[0].text); ``` Output: ``` { "id": "req_06", "content": [ {"type": "tool_call", "id": "call_01", "name": "get_free_slots", "input": {"week": "next"}} ], "stop_reason": "tool_call", "usage": {"input_tokens": 88, "output_tokens": 21} } ``` The output shows the first reply, the one that asks for the function. After you send the result, the next reply has `stop_reason` of `end_turn` and holds the answer as text. ## Parameters - `tools` (array, optional): The functions she may ask you to call. - `tools.name` (text, required): A short name for the function. - `tools.description` (text, required): What the function does and when to use it. She reads this to decide. - `tools.input_schema` (object, required): A JSON schema for the function's input. - `tool_choice` (object, optional): How freely she may use tools. `auto` lets her decide and is the default, `none` stops her using tools, `any` makes her use one, and {"type": "tool", "name": "..."} makes her use that tool. ## Next steps - [Structured output](https://antarya.ai/docs/guides/structured-output.md): Get a reply in a fixed JSON shape. - [Conversations](https://antarya.ai/docs/guides/conversations.md): How the history you send back is built. - [Errors](https://antarya.ai/docs/api.md): What to do when a request fails. --- Source: https://antarya.ai/docs/guides/files-and-images # Files and images > Upload a file once and use it in messages, or send a file or an image inside the request. ## What it is for Some questions need a document or a picture. Upload a file to `/v1/files`, then refer to it by id in any message. A file or an image can also go inside the message itself, read for that request only and not stored. ## Upload and use a file ```bash curl https://antarya.ai/v1/files \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -F file=@agreement.pdf curl https://antarya.ai/v1/chat \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "messages": [ { "role": "user", "content": [ {"type": "file", "file_id": "file_01"}, {"type": "text", "text": "Summarise the termination clause in this agreement."} ] } ] }' ``` ```python from antarya import Antarya client = Antarya() file = client.files.create(file=open("agreement.pdf", "rb")) reply = client.chat.create( messages=[{ "role": "user", "content": [ {"type": "file", "file_id": file.id}, {"type": "text", "text": "Summarise the termination clause in this agreement."}, ], }], ) print(reply.content[0].text) ``` ```typescript import fs from "node:fs"; import Antarya from "antarya"; const client = new Antarya(); const file = await client.files.create({ file: fs.createReadStream("agreement.pdf") }); const reply = await client.chat.create({ messages: [{ role: "user", content: [ { type: "file", file_id: file.id }, { type: "text", text: "Summarise the termination clause in this agreement." }, ], }], }); console.log(reply.content[0].text); ``` ```bash antarya --file agreement.pdf "Summarise the termination clause in this agreement." ``` Output: ``` { "id": "req_07", "content": [ {"type": "text", "text": "Either party can end the agreement with 30 days of written notice..."} ], "stop_reason": "end_turn", "usage": {"input_tokens": 1204, "output_tokens": 61} } ``` ## Send a file without storing it A file part can also hold the file itself as base64 text, with its name and media type. It is read for that request only and is not stored, so there is nothing to delete afterwards. The same types and the 10 MB limit apply. ```python import base64 with open("agreement.pdf", "rb") as f: data = base64.b64encode(f.read()).decode() reply = client.chat.create( messages=[{ "role": "user", "content": [ {"type": "file", "source": {"type": "base64", "filename": "agreement.pdf", "media_type": "application/pdf", "data": data}}, {"type": "text", "text": "Summarise the termination clause in this agreement."}, ], }], ) ``` ```typescript import fs from "node:fs"; const data = fs.readFileSync("agreement.pdf").toString("base64"); const reply = await client.chat.create({ messages: [{ role: "user", content: [ { type: "file", source: { type: "base64", filename: "agreement.pdf", media_type: "application/pdf", data } }, { type: "text", text: "Summarise the termination clause in this agreement." }, ], }], }); ``` ## Send an image inline An image part holds the picture as base64 text, with its media type. ```python import base64 with open("signature-page.png", "rb") as f: data = base64.b64encode(f.read()).decode() reply = client.chat.create( messages=[{ "role": "user", "content": [ {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": data}}, {"type": "text", "text": "Who signed this page?"}, ], }], ) ``` ```typescript import fs from "node:fs"; const data = fs.readFileSync("signature-page.png").toString("base64"); const reply = await client.chat.create({ messages: [{ role: "user", content: [ { type: "image", source: { type: "base64", media_type: "image/png", data } }, { type: "text", text: "Who signed this page?" }, ], }], }); ``` ## Manage files `GET /v1/files` lists your files, `GET /v1/files/{id}` describes one and `DELETE /v1/files/{id}` removes it. Delete a file when you no longer need it. ## Parameters - `file` (file, required): The file to upload, sent as multipart form data to POST /v1/files. - `messages.content` (array, optional): A list of parts, to put a file, image or text in one message. - `messages.content.type` (text, required): "text", "image" or "file". - `messages.content.file_id` (text, optional): The id returned by an upload. Used with the "file" part. - `messages.content.source` (object, optional): Data sent inside the message, with type "base64", a media_type and the data. Used with the "image" part, and with the "file" part in place of file_id, where it also needs a filename. ## Limits A file can be up to 10 MB and an account can store up to 100 MB during early access. A file over either limit gets a 413. An image over 10 MB gets a 413. More than 20 images in a request, or an image that is not PNG, JPEG or WebP, gets a 400 `invalid_request`. | Limit | Value | |---|---| | File size | 10 MB a file | | File types | txt, md, csv, json, pdf, docx, doc, xlsx | | Image types | PNG, JPEG and WebP | | Image size | 10 MB each, up to 20 images in a request | | Stored per account | 100 MB in total | ## Next steps - [Counting tokens](https://antarya.ai/docs/guides/counting-tokens.md): See what a file adds to a request before you send it. - [Batch](https://antarya.ai/docs/guides/batch.md): Run the same question over many files. - [CLI](https://antarya.ai/docs/cli.md): Attach files from your terminal. --- Source: https://antarya.ai/docs/guides/batch # Batch > Send many requests at once and collect the replies later. ## What it is for When you have many requests and do not need the answers straight away, send them as one batch. Antarya works through them in the background, and you collect the replies when the batch is done. Batch requests are billed at their own price. ## Create a batch Each request in the batch has a `custom_id` you choose and the same body you would send to `/v1/chat`. ```bash curl https://antarya.ai/v1/batches \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "requests": [ { "custom_id": "contract-001", "params": {"messages": [{"role": "user", "content": "Summarise this contract'"'"'s termination clause."}]} }, { "custom_id": "contract-002", "params": {"messages": [{"role": "user", "content": "Draft a reply that declines the meeting."}]} } ] }' ``` ```python from antarya import Antarya client = Antarya() batch = client.batches.create(requests=[ { "custom_id": "contract-001", "params": {"messages": [{"role": "user", "content": "Summarise this contract's termination clause."}]}, }, { "custom_id": "contract-002", "params": {"messages": [{"role": "user", "content": "Draft a reply that declines the meeting."}]}, }, ]) print(batch.id, batch.status) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const batch = await client.batches.create({ requests: [ { custom_id: "contract-001", params: { messages: [{ role: "user", content: "Summarise this contract's termination clause." }] }, }, { custom_id: "contract-002", params: { messages: [{ role: "user", content: "Draft a reply that declines the meeting." }] }, }, ], }); console.log(batch.id, batch.status); ``` Output: ``` { "id": "batch_01", "status": "in_progress", "request_counts": {"total": 2, "done": 0} } ``` ## Collect the results `GET /v1/batches/{id}` returns the status. When it is `ended`, `GET /v1/batches/{id}/results` returns one line of JSON per request, each with its `custom_id` and either a `reply` or an `error`. See whether there is an `error` before you read `reply`. The lines may come in any order, so match them on `custom_id`. ```bash curl https://antarya.ai/v1/batches/batch_01 \ -H "Authorization: Bearer $ANTARYA_API_KEY" curl https://antarya.ai/v1/batches/batch_01/results \ -H "Authorization: Bearer $ANTARYA_API_KEY" ``` ```python batch = client.batches.get("batch_01") if batch.status == "ended": for line in client.batches.results("batch_01"): if line.error: print(line.custom_id, line.error.type, line.error.message) else: print(line.custom_id, line.reply.content[0].text) ``` ```typescript const batch = await client.batches.get("batch_01"); if (batch.status === "ended") { for await (const line of client.batches.results("batch_01")) { if (line.error) { console.log(line.custom_id, line.error.type, line.error.message); } else { console.log(line.custom_id, line.reply?.content[0]?.text); } } } ``` To stop a batch, call `POST /v1/batches/{id}/cancel`. Requests already finished keep their replies. ## Parameters - `requests` (array, required): The requests to run. - `requests.custom_id` (text, required): Your own label for the request. Each one in a batch must be different. - `requests.params` (object, required): The body of a chat request, with the same fields as POST /v1/chat except `stream` and `session_id`, which a batch request cannot use. ## Limits A batch holds up to 1,000 requests and its results arrive within 24 hours. A request still unrun after 24 hours comes back as a result line with an `error` of type `overloaded` and the message "This request did not run within 24 hours." There is no `expired` status. Results are kept for 30 days after the batch ends. An account can have 5 batches in progress and 10,000 queued requests. Calls to the batch endpoints count against the management limit in [rate limits](https://antarya.ai/docs/api/rate-limits.md); the requests inside a batch do not count against the chat limits. `cancel` stops the requests that have not run and the batch ends. | Limit | Value | |---|---| | Requests in one batch | 1,000 requests | | Time to finish | Within 24 hours | | Batches in progress | 5 an account | | Queued requests | 10,000 an account | | Batch price | To be announced | ## Next steps - [Counting tokens](https://antarya.ai/docs/guides/counting-tokens.md): Estimate the size of a batch before you send it. - [Rate limits](https://antarya.ai/docs/api.md): How many requests a key can make. - [Python SDK](https://antarya.ai/docs/sdk/python.md): Create and read batches from Python. --- Source: https://antarya.ai/docs/guides/counting-tokens # Counting tokens > Find out how many input tokens a request uses before you send it. ## What it is for Tokens are what you are billed for and how much a conversation can hold is measured in. To see how large a request is before you send it, post the same body to `/v1/count-tokens`. It returns `input_tokens` and does not produce a reply. Counting is free and not billed, and is limited to 100 a minute per key. The SDK methods are `client.chat.countTokens` in TypeScript and `client.chat.count_tokens` in Python. ## Count a request ```bash curl https://antarya.ai/v1/count-tokens \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "system": "Answer in plain English.", "messages": [ {"role": "user", "content": "Summarise this contract'"'"'s termination clause."} ] }' ``` ```python from antarya import Antarya client = Antarya() count = client.chat.count_tokens( system="Answer in plain English.", messages=[{"role": "user", "content": "Summarise this contract's termination clause."}], ) print(count.input_tokens) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const count = await client.chat.countTokens({ system: "Answer in plain English.", messages: [{ role: "user", content: "Summarise this contract's termination clause." }], }); console.log(count.input_tokens); ``` Output: ``` {"input_tokens": 23} ``` ## What it counts The count covers everything the request sends: `system`, every message, tool descriptions, a response schema, and files and images in the messages. It does not count the reply, which is only known afterwards in `usage.output_tokens`. ## Parameters - `messages` (array, required): The conversation to count, as in a chat request. - `system` (text, optional): Counted with the messages. - `tools` (array, optional): Counted with the messages. - `response_format` (object, optional): Counted with the messages. ## Limits | Limit | Value | |---|---| | Counting requests per minute | 100 a minute per key | | Cost of a count | Free, not billed | ## Next steps - [Models](https://antarya.ai/docs/models.md): How much a request can hold, and the longest reply. - [Files and images](https://antarya.ai/docs/guides/files-and-images.md): What an attachment adds to a request. - [Conversations](https://antarya.ai/docs/guides/conversations.md): Why a long history costs more each turn. --- Source: https://antarya.ai/docs/api # API reference > The base URL, authentication, request format and versioning for the Antarya API. ## Overview The Antarya API is a plain web API. Send JSON to `https://antarya.ai/v1` and read JSON back. Every endpoint below uses the same key, the same error shape and the same headers. | Endpoint | Purpose | |---|---| | `POST /v1/chat` | Reply to a conversation, as one body or as a stream. | | [`/v1/sessions`](https://antarya.ai/docs/api/sessions.md) | Keep a conversation on Antarya's side and add to it turn by turn. | | [`POST /v1/chat/completions`](https://antarya.ai/docs/api/openai-compatibility.md) | The OpenAI-shaped door, for clients written for OpenAI. | | `POST /v1/count-tokens` | Count the input tokens of a chat request. | | `/v1/files` | Upload, list, fetch and delete files for use in messages. | | `/v1/batches` | Run many chat requests at once and collect the replies later. | | `GET /v1/models` | List models and describe one. Paged lists (sessions and files) reply as `{object: "list", data, has_more}`. The models list is not paged and has no `has_more`. | ## Base URL ``` https://antarya.ai/v1 ``` ## Authentication Send your key in the `Authorization` header on every request. Keys start with `ak-`. Make one on the Keys page of the platform, and keep it out of code that runs in a browser. ```bash curl https://antarya.ai/v1/models \ -H "Authorization: Bearer $ANTARYA_API_KEY" ``` ```python from antarya import Antarya client = Antarya() # reads ANTARYA_API_KEY models = client.models.list() ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); // reads ANTARYA_API_KEY const models = await client.models.list(); ``` Output: ``` { "data": [ {"id": "antarya"} ] } ``` ## Requests and replies Bodies are JSON, sent with `Content-Type: application/json`. The one exception is a file upload, which is multipart form data. Replies are JSON, or server-sent events when a chat request sets `stream` to true. ## Request ids Every reply carries a `request-id` header. A failed request also returns the same value as `request_id` in its body. Include it when you write to support, and Antarya can find the request. ## Versioning The version is part of the path. `/v1` stays as it is: new fields and new endpoints can appear in it, and nothing in it is removed or renamed. A change that breaks existing requests ships as `/v2`, and `/v1` keeps working alongside it. Write your code to ignore fields it does not know. ## Next steps - [Chat](https://antarya.ai/docs/api/chat.md): Send a conversation and read the reply. - [Errors](https://antarya.ai/docs/api/errors.md): Every status, its type and what to do. - [Rate limits](https://antarya.ai/docs/api/rate-limits.md): How many requests a key and an account can make. --- Source: https://antarya.ai/docs/api/chat # Chat > POST /v1/chat replies to a conversation, as one body or as a stream of events. ## Create a reply `POST https://antarya.ai/v1/chat` Send the conversation so far. Antarya returns the next reply. Pass `session_id` to continue a stored session, which is covered in [sessions](https://antarya.ai/docs/api/sessions.md). The guides cover the larger features one at a time: [conversations](https://antarya.ai/docs/guides/conversations.md), [streaming](https://antarya.ai/docs/guides/streaming.md), [structured output](https://antarya.ai/docs/guides/structured-output.md), [tool use](https://antarya.ai/docs/guides/tool-use.md) and [files and images](https://antarya.ai/docs/guides/files-and-images.md). ### Headers | Header | Value | |---|---| | `Authorization` | `Bearer $ANTARYA_API_KEY` | | `Content-Type` | `application/json` | ```bash curl https://antarya.ai/v1/chat \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "antarya", "system": "Answer in plain English.", "messages": [ {"role": "user", "content": "Summarise this contract'"'"'s termination clause."} ], "max_output_tokens": 400 }' ``` ```python from antarya import Antarya client = Antarya() reply = client.chat.create( model="antarya", system="Answer in plain English.", messages=[{"role": "user", "content": "Summarise this contract's termination clause."}], max_output_tokens=400, ) print(reply.content[0].text) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const reply = await client.chat.create({ model: "antarya", system: "Answer in plain English.", messages: [{ role: "user", content: "Summarise this contract's termination clause." }], max_output_tokens: 400, }); console.log(reply.content[0].text); ``` Output: ``` { "id": "req_01", "model": "antarya", "content": [ {"type": "text", "text": "Either side can end the agreement with 30 days of written notice."} ], "stop_reason": "end_turn", "usage": {"input_tokens": 24, "output_tokens": 17} } ``` ## Request body - `model` (text, optional): The id or alias of the model. Leave it out to use the current default. - `messages` (array, required): The conversation, oldest message first. - `messages.role` (text, required): "user", "assistant" or "tool". - `messages.content` (text or array, required): Plain text, or a list of parts. A part is text, an image, a file, a tool_call or a tool_result. The parts are listed under [message parts](#parts), and [files and images](https://antarya.ai/docs/guides/files-and-images.md) shows them in use. - `session_id` (text, optional): The id of a [stored session](https://antarya.ai/docs/guides/sessions.md). Its saved turns go before `messages`, and on success the new turns and the reply are saved to it. A failed or refused request saves nothing. - `include_thinking` (boolean, optional): Set to true to get short thinking notes with the reply. The default is false. A whole reply carries them as `thinking`, and a stream sends them as `thinking` events. - `system` (text, optional): Instructions that apply to the whole conversation. - `max_output_tokens` (number, optional): The most tokens the reply may hold. The reply stops there if it reaches the limit. - `stream` (boolean, optional): Set to true to receive server-sent events. The default is false. - `tools` (array, optional): Functions she may ask you to call. Each has a name, a description and an input_schema. - `tool_choice` (object, optional): How freely she may use tools. `auto` lets her decide and is the default, `none` stops her using tools, `any` makes her use one, and {"type": "tool", "name": "..."} makes her use that tool. - `response_format` (object, optional): A JSON schema the reply must follow, as {"type": "json_schema", "schema": {...}}. The schema may use the keywords type, properties, required, items, enum, description and additionalProperties. - `metadata` (object, optional): Your own labels for the request, up to 16 string pairs, with keys up to 64 characters and values up to 512 characters. They are kept with the usage record. They are never sent to the model. ### Message parts | Part | Shape | Limits | |---|---|---| | Text | `{"type": "text", "text": "..."}` | | | File, by id | `{"type": "file", "file_id": "file_..."}` | A file uploaded to [/v1/files](https://antarya.ai/docs/api/files.md). | | File, inline | `{"type": "file", "source": {"type": "base64", "filename": "agreement.pdf", "media_type": "application/pdf", "data": "..."}}` | Up to 10 MB decoded. Read for this request only and not stored. | | Image | `{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "..."}}` | PNG, JPEG or WebP, up to 10 MB each and 20 a request. | ## Response - `id` (text, required): The id of this reply. - `model` (text, required): The model that wrote the reply. - `content` (array, required): The reply, as a list of parts. - `content.type` (text, required): "text" or "tool_call". - `content.text` (text, optional): The words of a text part. - `stop_reason` (text, required): Why the reply ended. See the table below. - `thinking` (array, optional): Only when `include_thinking` is true. A list of notes, each with a `step`, a `stage` (a short label) and a `summary`. - `usage` (object, required): What the request used. - `usage.input_tokens` (number, required): Tokens in everything you sent. - `usage.output_tokens` (number, required): Tokens in the reply. | `stop_reason` | Meaning | |---|---| | `end_turn` | Antarya finished the reply. | | `max_output_tokens` | The reply reached `max_output_tokens` and stopped. | | `tool_call` | The reply asks you to run a function. Send the result back. | A reply cut off at `max_output_tokens` ends with that value, including a JSON reply, which is then not complete. ## Streaming With `stream` set to true, the response is a stream of server-sent events. The events are `reply.start`, `content.delta`, `reply.done` and `error`, and `thinking` when `include_thinking` is true. The [streaming guide](https://antarya.ai/docs/guides/streaming.md) shows each one and the data it carries. ``` event: reply.start data: {"id": "req_03", "model": "antarya"} event: content.delta data: {"index": 0, "type": "text", "text": "Thank you for the invitation. "} event: reply.done data: {"stop_reason": "end_turn", "usage": {"input_tokens": 14, "output_tokens": 19}} ``` ## Not yet available `system`, `tools` and `response_format` are not available on this model yet. Each turns on when the model object's `capabilities` flag (`system`, `tools`, `structured_output`) is true. ## Limits The model reports a longest reply of 2,048 tokens. | Limit | Value | |---|---| | Longest reply | 2,048 tokens (`max_output_tokens` on the `antarya` model) | ## Next steps - [Count tokens](https://antarya.ai/docs/api/count-tokens.md): Measure a request before you send it. - [Errors](https://antarya.ai/docs/api/errors.md): What each failure looks like. - [Quickstart](https://antarya.ai/docs/quickstart.md): Send a first request. - [Sessions](https://antarya.ai/docs/api/sessions.md): Keep a conversation on Antarya's side. - [OpenAI compatibility](https://antarya.ai/docs/api/openai-compatibility.md): Use OpenAI's clients with two changed lines. --- Source: https://antarya.ai/docs/api/sessions # Sessions > Create, list, fetch and delete stored sessions that keep a conversation on Antarya's side. ## Create a session `POST https://antarya.ai/v1/sessions` A session holds the turns of one conversation. Create it, then pass its id as `session_id` on [`/v1/chat`](https://antarya.ai/docs/api/chat.md). The [guide](https://antarya.ai/docs/guides/sessions.md) shows the whole path. ```bash curl https://antarya.ai/v1/sessions \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{"metadata": {"matter": "supply-agreement"}}' ``` ```python from antarya import Antarya client = Antarya() session = client.sessions.create(metadata={"matter": "supply-agreement"}) print(session.id) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const session = await client.sessions.create({ metadata: { matter: "supply-agreement" } }); console.log(session.id); ``` Output: ``` { "id": "sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31", "object": "session", "created_at": "2026-11-27T09:30:00Z", "updated_at": "2026-11-27T09:30:00Z", "metadata": {"matter": "supply-agreement"} } ``` - `metadata` (object, optional): Up to 16 key and value pairs of your own, such as a matter name. Keys are at most 64 characters and values at most 512. ## The session object - `id` (text, required): The id to pass as session_id, such as sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31. It is `sess_` followed by 32 lowercase hex characters. - `object` (text, required): Always "session". - `created_at` (text, required): When the session was created, as an ISO 8601 time. - `updated_at` (text, required): When a turn was last saved to it, as an ISO 8601 time. - `metadata` (object, required): The pairs you set when you created it. - `messages` (array, optional): The saved turns, oldest first. Only on a fetch of one session. ## List, fetch and delete | Request | Does | |---|---| | `GET /v1/sessions` | Lists your sessions, newest first, in pages. | | `GET /v1/sessions/{id}` | Returns one session object with its `messages`. | | `DELETE /v1/sessions/{id}` | Deletes the session and the turns stored in it. | ```bash curl "https://antarya.ai/v1/sessions?limit=20" \ -H "Authorization: Bearer $ANTARYA_API_KEY" # the id comes from the create reply curl https://antarya.ai/v1/sessions/sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31 \ -H "Authorization: Bearer $ANTARYA_API_KEY" curl -X DELETE https://antarya.ai/v1/sessions/sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31 \ -H "Authorization: Bearer $ANTARYA_API_KEY" ``` ```python sessions = client.sessions.list(limit=20) for s in sessions.data: print(s.id) if sessions.has_more: next_page = client.sessions.list(limit=20, after=sessions.data[-1].id) session = client.sessions.get("sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31") print(session.messages) client.sessions.delete("sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31") ``` ```typescript const sessions = await client.sessions.list({ limit: 20 }); for (const s of sessions.data) console.log(s.id); if (sessions.has_more) { const nextPage = await client.sessions.list({ limit: 20, after: sessions.data.at(-1)!.id }); } const session = await client.sessions.get("sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31"); console.log(session.messages); await client.sessions.delete("sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31"); ``` Output: ``` { "id": "sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31", "deleted": true } ``` ## Paging A list returns at most `limit` sessions, newest first. The reply is `{"object": "list", "data": [...], "has_more": true}`. When `has_more` is true there is another page: pass the id of the last session you received as `after` to get it. - `limit` (number, optional): How many sessions to return. The default is 20 and the most is 100. - `after` (text, optional): A session id. The list continues with the sessions after it. ## Limits | Limit | Value | |---|---| | Sessions an account | 1,000 | | Who can use a session | Every key on the account | - Creating a session past 1,000 is a 400 `invalid_request`: "An account can hold up to 1,000 sessions. Delete one to make room." - A session of another account is a 403 `permission_error`. An unknown id is a 404 `not_found`. A bad `after` is a 400. - On success, `/v1/chat` saves the new turns and the reply. A failed or refused request saves nothing. - Management requests share the 60 a minute per key allowance in [rate limits](https://antarya.ai/docs/api/rate-limits.md). ## Next steps - [Sessions guide](https://antarya.ai/docs/guides/sessions.md): Create a session and continue it turn by turn. - [Chat](https://antarya.ai/docs/api/chat.md): Pass session_id on a chat request. - [Errors](https://antarya.ai/docs/api/errors.md): Every status and what to do about it. --- Source: https://antarya.ai/docs/api/count-tokens # Count tokens > POST /v1/count-tokens returns the input tokens of a chat request without writing a reply. ## Count a request `POST https://antarya.ai/v1/count-tokens` Send the body you would send to [`/v1/chat`](https://antarya.ai/docs/api/chat.md). Antarya returns the number of input tokens and does not write a reply. Counting is free and is not billed. It is limited to 100 a minute per key, apart from the [chat limits](https://antarya.ai/docs/api/rate-limits.md). The [guide](https://antarya.ai/docs/guides/counting-tokens.md) explains what the count covers. ### Headers | Header | Value | |---|---| | `Authorization` | `Bearer $ANTARYA_API_KEY` | | `Content-Type` | `application/json` | ```bash curl https://antarya.ai/v1/count-tokens \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "messages": [ {"role": "user", "content": "Draft a reply that declines the meeting."} ] }' ``` ```python from antarya import Antarya client = Antarya() count = client.chat.count_tokens( messages=[{"role": "user", "content": "Draft a reply that declines the meeting."}], ) print(count.input_tokens) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const count = await client.chat.countTokens({ messages: [{ role: "user", content: "Draft a reply that declines the meeting." }], }); console.log(count.input_tokens); ``` Output: ``` {"input_tokens": 12} ``` ## Request body - `messages` (array, required): The conversation to count, as in a chat request. - `model` (text, optional): The id or alias of the model. Models can count tokens differently. - `system` (text, optional): Counted with the messages. - `tools` (array, optional): Counted with the messages. - `response_format` (object, optional): Counted with the messages. ## Response - `input_tokens` (number, required): The tokens the request would use as input. ## Next steps - [Chat](https://antarya.ai/docs/api/chat.md): Send the request once you know its size. - [Counting tokens guide](https://antarya.ai/docs/guides/counting-tokens.md): What the count covers. - [Rate limits](https://antarya.ai/docs/api/rate-limits.md): How many requests a key can make. --- Source: https://antarya.ai/docs/api/files # Files > Upload, list, fetch and delete files to use in chat messages. ## Upload a file `POST https://antarya.ai/v1/files` Send the file as multipart form data in the field `file`. Antarya returns the file object, with its id, which you put in a `file` part of a message. The [guide](https://antarya.ai/docs/guides/files-and-images.md) shows the whole path. ### Headers | Header | Value | |---|---| | `Authorization` | `Bearer $ANTARYA_API_KEY` | | `Content-Type` | `multipart/form-data`, set by your client | ```bash curl https://antarya.ai/v1/files \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -F file=@agreement.pdf ``` ```python from antarya import Antarya client = Antarya() file = client.files.create(file=open("agreement.pdf", "rb")) print(file.id) ``` ```typescript import fs from "node:fs"; import Antarya from "antarya"; const client = new Antarya(); const file = await client.files.create({ file: fs.createReadStream("agreement.pdf") }); console.log(file.id); ``` Output: ``` { "id": "file_01", "filename": "agreement.pdf", "size": 48213, "created_at": "2026-11-27T09:30:00Z" } ``` - `file` (file, required): The file to upload. ## The file object - `id` (text, required): The id to use in a message part, such as file_01. - `filename` (text, required): The name the file was uploaded with. - `size` (number, required): The size in bytes. - `created_at` (text, required): When the file was uploaded, as an ISO 8601 time. ## List, fetch and delete | Request | Does | |---|---| | `GET /v1/files` | Lists your files, newest first. | | `GET /v1/files/{id}` | Returns one file object. | | `DELETE /v1/files/{id}` | Deletes the file. Messages that already used it keep their replies. | ```bash curl https://antarya.ai/v1/files \ -H "Authorization: Bearer $ANTARYA_API_KEY" curl -X DELETE https://antarya.ai/v1/files/file_01 \ -H "Authorization: Bearer $ANTARYA_API_KEY" ``` ```python files = client.files.list() client.files.delete("file_01") ``` ```typescript const files = await client.files.list(); await client.files.delete("file_01"); ``` Output: ``` {"id": "file_01", "deleted": true} ``` The file object is `{id, object, filename, media_type, size, created_at}`, and `id` starts with `file_`. Deleting a file returns `{"id": "file_01", "deleted": true}`. A message with a file or an image is refused when the model's `files` or `images` capability is false. ## Limits A file can be up to 10 MB and an account can store up to 100 MB during early access. A file or an upload over either limit gets a 413. | Limit | Value | |---|---| | File size | 10 MB a file | | File types | txt, md, csv, json, pdf, docx, doc, xlsx | | Stored per account | 100 MB in total | ## Next steps - [Files and images guide](https://antarya.ai/docs/guides/files-and-images.md): Use an uploaded file in a message. - [Chat](https://antarya.ai/docs/api/chat.md): The message parts a file goes in. - [Errors](https://antarya.ai/docs/api/errors.md): What a failed upload returns. --- Source: https://antarya.ai/docs/api/batches # Batches > Create a batch of chat requests, read its status and collect the results. ## Create a batch `POST https://antarya.ai/v1/batches` Send a list of chat requests, each with a `custom_id` you choose. Antarya runs them in the background, billed at the batch rate. The [guide](https://antarya.ai/docs/guides/batch.md) walks through the whole cycle. ### Headers | Header | Value | |---|---| | `Authorization` | `Bearer $ANTARYA_API_KEY` | | `Content-Type` | `application/json` | ```bash curl https://antarya.ai/v1/batches \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "requests": [ { "custom_id": "contract-001", "params": {"messages": [{"role": "user", "content": "Summarise this contract'"'"'s termination clause."}]} } ] }' ``` ```python from antarya import Antarya client = Antarya() batch = client.batches.create(requests=[ { "custom_id": "contract-001", "params": {"messages": [{"role": "user", "content": "Summarise this contract's termination clause."}]}, }, ]) print(batch.id, batch.status) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const batch = await client.batches.create({ requests: [ { custom_id: "contract-001", params: { messages: [{ role: "user", content: "Summarise this contract's termination clause." }] }, }, ], }); console.log(batch.id, batch.status); ``` Output: ``` { "id": "batch_01", "status": "in_progress", "request_counts": {"total": 1, "done": 0} } ``` - `requests` (array, required): The requests to run. - `requests.custom_id` (text, required): Your own label for the request. Each one in a batch must be different. - `requests.params` (object, required): The body of a chat request, with the same fields as POST /v1/chat except `stream` and `session_id`, which a batch request cannot use. ## The batch object - `id` (text, required): The id of the batch, such as batch_01. - `status` (text, required): "in_progress" while requests are running, "ended" when all have finished or the batch was cancelled. - `request_counts` (object, required): How many requests the batch holds and how many have finished. - `request_counts.total` (number, required): Requests in the batch. - `request_counts.done` (number, required): Requests that have a reply or an error. ## Read, collect and cancel | Request | Does | |---|---| | `GET /v1/batches/{id}` | Returns the batch object. | | `GET /v1/batches/{id}/results` | Once the status is `ended`, returns one line of JSON per request, each with its `custom_id` and either a `reply` or an `error`. Read `error` first. The lines may come in any order. | | `POST /v1/batches/{id}/cancel` | Stops the requests that have not run. Finished requests keep their replies. | ```bash curl https://antarya.ai/v1/batches/batch_01/results \ -H "Authorization: Bearer $ANTARYA_API_KEY" ``` ```python for line in client.batches.results("batch_01"): if line.error: print(line.custom_id, line.error.type, line.error.message) else: print(line.custom_id, line.reply.content[0].text) ``` ```typescript for await (const line of client.batches.results("batch_01")) { if (line.error) { console.log(line.custom_id, line.error.type, line.error.message); } else { console.log(line.custom_id, line.reply?.content[0]?.text); } } ``` Output: ``` {"custom_id": "contract-001", "reply": {"id": "req_09", "model": "antarya", "content": [{"type": "text", "text": "Either side can end the agreement with 30 days of written notice."}], "stop_reason": "end_turn", "usage": {"input_tokens": 24, "output_tokens": 17}}} {"custom_id": "contract-002", "error": {"type": "overloaded", "message": "This request did not run within 24 hours."}} ``` ## Limits A batch holds up to 1,000 requests and its results arrive within 24 hours. A request still unrun after 24 hours comes back as a result line with an `error` of type `overloaded` and the message "This request did not run within 24 hours." A request cancelled before it ran comes back as an `error` of type `invalid_request`. The batch object has only the statuses `in_progress` and `ended`. Results are kept for 30 days after the batch ends. An account can have 5 batches in progress and 10,000 queued requests. Calls to the batch endpoints count against the management limit in [rate limits](https://antarya.ai/docs/api/rate-limits.md); the requests inside a batch do not count against the chat limits. | Limit | Value | |---|---| | Requests in one batch | 1,000 requests | | Time to finish | Within 24 hours | | Batches in progress | 5 an account | | Queued requests | 10,000 an account | | Batch price | To be announced | ## Next steps - [Batch guide](https://antarya.ai/docs/guides/batch.md): Create a batch and collect its replies. - [Rate limits](https://antarya.ai/docs/api/rate-limits.md): How many requests a key can make. - [Chat](https://antarya.ai/docs/api/chat.md): The body each batch request takes. --- Source: https://antarya.ai/docs/api/models # Models > GET /v1/models lists the models your key can use and describes each one. ## List models `GET https://antarya.ai/v1/models` Returns the models your key can use. `GET /v1/models/{id}` returns one. The [Models page](https://antarya.ai/docs/models.md) explains ids and aliases. ### Headers | Header | Value | |---|---| | `Authorization` | `Bearer $ANTARYA_API_KEY` | ```bash curl https://antarya.ai/v1/models \ -H "Authorization: Bearer $ANTARYA_API_KEY" curl https://antarya.ai/v1/models/antarya \ -H "Authorization: Bearer $ANTARYA_API_KEY" ``` ```python from antarya import Antarya client = Antarya() models = client.models.list() model = client.models.get("antarya") print(model.id) ``` ```typescript import Antarya from "antarya"; const client = new Antarya(); const models = await client.models.list(); const model = await client.models.get("antarya"); console.log(model.id); ``` Output: ``` { "object": "list", "data": [ {"id": "antarya", "object": "model"} ] } ``` Fetching one model returns its model object, with the fields below. ```bash curl https://antarya.ai/v1/models/antarya \ -H "Authorization: Bearer $ANTARYA_API_KEY" ``` Output: ``` { "id": "antarya", "object": "model", "created": 1795737600, "owned_by": "antarya", "max_output_tokens": 2048, "inputs": ["text", "image", "file"], "capabilities": { "conversations": true, "images": true, "files": true, "streaming": true, "thinking": true, "system": false, "tools": false, "structured_output": false, "artifacts": false } } ``` ## The model object - `id` (text, required): The id or alias to send in the model field of a chat request. - `object` (text, required): Always model. - `created` (number, required): When the model was released, as a Unix time in seconds. - `owned_by` (text, required): Always antarya. - `max_output_tokens` (number, required): The longest reply, in tokens. Today 2,048. - `inputs` (array, required): What a message can hold, from text, image and file. - `capabilities` (object, required): A true or false flag for each of conversations, images, files, streaming, thinking, system, tools, structured_output and artifacts. A flag that is false is not available on this model yet. ## Next steps - [Models](https://antarya.ai/docs/models.md): Ids, aliases and the model's limits. - [Chat](https://antarya.ai/docs/api/chat.md): Send the id in a request. - [Errors](https://antarya.ai/docs/api/errors.md): What a request for an unknown model returns. --- Source: https://antarya.ai/docs/api/errors # Errors > The error body, every status the API returns, and what to do about each. ## The error body A failed request returns an HTTP status and a JSON body in one shape. `type` names the kind of failure and stays the same between releases, so branch on it. `message` is for people and may change. `request_id` matches the `request-id` header; send it to support when you ask about a request. ```json { "error": { "type": "invalid_request", "message": "messages must hold at least one message." }, "request_id": "req_01" } ``` A request that fails before a stream begins returns this body with an ordinary status. A failure after the stream has begun arrives as an `error` event with the same body. ## Statuses | Status | Type | Cause | Fix | |---|---|---|---| | 400 | `invalid_request` | The body is not valid JSON, a field is missing, or a value has the wrong type. | Read `message`, correct the body and send it again. | | 401 | `authentication_error` | The key is missing, mistyped or revoked. | Look at the `Authorization` header and the key on the Keys page. Make a new key if it was revoked. | | 403 | `permission_error` | The key is valid but not allowed to do this, such as reading another account's file. | Use a key from the account that owns the resource. | | 404 | `not_found` | The path, or the id of a model, file, batch or session, does not exist. | Look at the id and the path. List files, sessions or models to find the right one. | | 413 | `request_too_large` | The request is larger than the endpoint accepts. | Send less text or fewer files. Count tokens first to see the size. | | 429 | `rate_limit_error` | The key or the account has used its allowance for now. | Retry after the time in the `retry-after` header. See [rate limits](https://antarya.ai/docs/api/rate-limits.md). | | 500 | `api_error` | Something went wrong on Antarya's side. | Retry after a short wait. If it keeps failing, send the `request_id` to support. | | 503 | `overloaded` | Antarya is busy and cannot take the request now. The message reads "Antarya is busy. Try again in a moment." | Retry after a short wait, a little longer each time. | ## Retrying Retry 429, 500 and 503. Wait for `retry-after` when the reply has it, and wait a little longer after each further failure. Do not retry 400, 401, 403, 404 or 413: the same request fails the same way. The Python and TypeScript SDKs retry these statuses for you. ## Next steps - [Rate limits](https://antarya.ai/docs/api/rate-limits.md): The 429 body and the headers that tell you when to retry. - [Python SDK](https://antarya.ai/docs/sdk/python.md): Errors and retries from Python. - [TypeScript SDK](https://antarya.ai/docs/sdk/typescript.md): Errors and retries from TypeScript. --- Source: https://antarya.ai/docs/api/rate-limits # Rate limits > How many requests and tokens a key and an account can use, and what a 429 reply tells you. ## Two limits Limits apply to each key and to the account that owns it. A request is turned away when either one is used up. The account limit is shared by all of its keys. | Limit | Per key | Per account | |---|---|---| | Requests per minute | 20 | 30 | | Requests per day | 500 | 1,000 | | Input tokens per minute | 40,000 | 60,000 | | Output tokens per minute | 8,000 | 16,000 | There is one early-access tier today. A key can send 20 requests per minute and 500 a day. Counting tokens is free and has its own limit of 100 a minute per key. Management endpoints, such as listing models and files, are limited to 60 a minute per key. Calls to the [batch](https://antarya.ai/docs/api/batches.md) endpoints count against the 60 a minute management limit; the requests inside a batch do not count against the chat limits. An account can have at most 5 batches in progress and 10,000 queued requests. ## Headers Every reply carries the limit its endpoint is under: the chat requests-per-minute allowance for chat, the 100 a minute window for counting tokens, and the 60 a minute window for management endpoints such as sessions, files, models and batches. | Header | Meaning | |---|---| | `ratelimit-limit` | The most requests allowed in the current window. | | `ratelimit-remaining` | Requests left in the window. | | `ratelimit-reset` | Seconds until the window resets. | | `retry-after` | On a 429 only: seconds to wait before you try again. | ## When you reach a limit The reply is a 429 with the usual error body and a `retry-after` header. ```bash curl -i https://antarya.ai/v1/chat \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{"messages": [{"role": "user", "content": "Draft a reply that declines the meeting."}]}' ``` Output: ``` HTTP/1.1 429 Too Many Requests retry-after: 20 ratelimit-remaining: 0 { "error": { "type": "rate_limit_error", "message": "Too many requests for this key. Retry after 20 seconds." }, "request_id": "req_02" } ``` The message names the limit that was hit, in the form "Too many {what} for this {key|account}. Retry after N seconds." Wait for `retry-after`, then send the request again. Spread large jobs over time, or send them as a [batch](https://antarya.ai/docs/api/batches.md), which has its own allowance. ## Ask for more Open the Usage page on the platform to see how close you are to each limit. To raise a limit, send a request at [/contact](https://antarya.ai/contact) with your account, the limit you reach and the volume you expect. ## Next steps - [Errors](https://antarya.ai/docs/api/errors.md): Every status and what to do about it. - [Batches](https://antarya.ai/docs/api/batches.md): Send many requests without hitting a per-minute limit. - [Chat](https://antarya.ai/docs/api/chat.md): The request these limits apply to. --- Source: https://antarya.ai/docs/api/openai-compatibility # OpenAI compatibility > Use OpenAI's Python and TypeScript clients with Antarya by changing two lines. ## Change two lines `POST https://antarya.ai/v1/chat/completions` takes the OpenAI chat request and returns the OpenAI reply. If your code already uses an OpenAI client, change the base URL and the key. Use a key from the Keys page, and the model `antarya`. ```python import os from openai import OpenAI client = OpenAI( base_url="https://antarya.ai/v1", # changed api_key=os.environ["ANTARYA_API_KEY"], # changed ) reply = client.chat.completions.create( model="antarya", messages=[{"role": "user", "content": "Draft a reply that declines the meeting."}], ) print(reply.choices[0].message.content) ``` ```typescript import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://antarya.ai/v1", // changed apiKey: process.env.ANTARYA_API_KEY, // changed }); const reply = await client.chat.completions.create({ model: "antarya", messages: [{ role: "user", content: "Draft a reply that declines the meeting." }], }); console.log(reply.choices[0].message.content); ``` ```bash curl https://antarya.ai/v1/chat/completions \ -H "Authorization: Bearer $ANTARYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "antarya", "messages": [{"role": "user", "content": "Draft a reply that declines the meeting."}] }' ``` Output: ``` { "id": "req_01", "object": "chat.completion", "model": "antarya", "choices": [ { "index": 0, "message": {"role": "assistant", "content": "Thank you for the invitation. I am unable to attend..."}, "finish_reason": "stop" } ], "usage": {"prompt_tokens": 14, "completion_tokens": 19, "total_tokens": 33} } ``` ## Accepted fields | Field | Notes | |---|---| | `messages` | Roles `system`, `developer`, `user`, `assistant` and `tool`. Content is a string or a list of parts (`text`, `image_url`). System and developer messages are not available on this model yet: they are refused until the model object's `capabilities.system` is true. | | `model` | Use `antarya`. | | `max_tokens`, `max_completion_tokens` | The longest reply to write. | | `stream`, `stream_options.include_usage` | Stream the reply, and ask for the usage in the last chunk. | | `tools`, `tool_choice` | Function tools. | | `response_format` | `json_schema` or `json_object`. | | `metadata` | Pairs of your own. | | `include_thinking` | An extra field that is not part of OpenAI's request. Set it to true to get thinking notes as `reasoning_content`. In Python, pass it as `extra_body={"include_thinking": True}`. In TypeScript, add it to the request object as a plain field. | Abilities and refusals are the same as on `/v1/chat`. A field for an ability the model does not have yet, such as `tools` or `response_format`, is refused in the same way. See `capabilities` on the [model object](https://antarya.ai/docs/api/models.md). ## Ignored fields `temperature`, `top_p`, `seed`, `user` and the other sampling fields are accepted and ignored, so existing code keeps working. They do not change the reply. `n` above 1 is a 400 `invalid_request_error`. Antarya writes one reply. ## The reply - `finish_reason` is `stop`, `length` (the reply reached the longest it may be) or `tool_calls`. - `usage` has `prompt_tokens`, `completion_tokens` and `total_tokens`. ## Streaming With `stream` set to true, the reply is a series of `chat.completion.chunk` events. The id of every event is the request id. The last event is `data: [DONE]`. ``` data: {"id": "req_02", "object": "chat.completion.chunk", "created": 1795737700, "model": "antarya", "choices": [{"index": 0, "delta": {"role": "assistant", "content": ""}, "finish_reason": null}]} data: {"id": "req_02", "object": "chat.completion.chunk", "created": 1795737700, "model": "antarya", "choices": [{"index": 0, "delta": {"content": "Thank you "}, "finish_reason": null}]} data: {"id": "req_02", "object": "chat.completion.chunk", "created": 1795737700, "model": "antarya", "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]} data: [DONE] ``` If a request fails after the stream has started, the status is already sent. The server writes one data line with the error body (the shape in [errors](#errors)) and then `data: [DONE]`. ## Thinking notes Thinking notes come back as `reasoning_content`, an extra field on the message, and on each streamed delta, only when the request sets `include_thinking` to true. It is the field other OpenAI-compatible providers use, so a client that reads it works the same here. The notes are not counted as output tokens. See [chat](https://antarya.ai/docs/api/chat.md) for what the notes hold. ## Errors Errors use OpenAI's shape, with the same statuses as the [error page](https://antarya.ai/docs/api/errors.md). ```json { "error": { "message": "Too many requests for this key. Retry after 20 seconds.", "type": "requests", "param": null, "code": "rate_limit_exceeded" } } ``` | Status | `type` | `code` | |---|---|---| | 400 | `invalid_request_error` | null | | 401 | `invalid_request_error` | `invalid_api_key` | | 403 | `invalid_request_error` | `permission_denied` | | 404 | `invalid_request_error` | `not_found`, or `model_not_found` for an unknown model | | 413 | `invalid_request_error` | `request_too_large` | | 429 | `requests` | `rate_limit_exceeded` | | 500 | `server_error` | null | | 503 | `server_error` | `overloaded` | ## Next steps - [Chat](https://antarya.ai/docs/api/chat.md): The same model through Antarya's own request shape. - [Rate limits](https://antarya.ai/docs/api/rate-limits.md): The allowances that apply to both doors. - [Errors](https://antarya.ai/docs/api/errors.md): Every status and what to do about it. --- Source: https://antarya.ai/docs/changelog # Changelog > What changed in the Antarya API, the apps and the SDKs, newest first. ## Releases ### 27 November 2026: The /v1 API, the SDKs and the CLI The /v1 API is live with sessions, files, batches, count-tokens and models. Sessions keep a conversation on Antarya's side. `/v1/chat/completions` accepts requests from OpenAI clients. The TypeScript SDK is on npm and the Python SDK is on PyPI, both as `antarya`, and the CLI is available. ### 27 November 2026: Early access Antarya opens in early access, in the app at antarya.ai and through the API at https://antarya.ai/v1. The API has chat, streaming, files, images, token counting and models. ## Next steps - [Quickstart](https://antarya.ai/docs/quickstart.md): Make a key and send a first request. - [API reference](https://antarya.ai/docs/api.md): Every endpoint, with its parameters and replies.