API REFERENCE
Agents API
Run agentic work on the OpenAI-compatible API: the :agents model suffix executes each turn in your organization's sandbox with tools, files, documents, and durable conversations.
Overview
The Agents API runs agentic work through the same OpenAI-compatible endpoints you already call. Execution is selected by the :agents suffix on the model string, so the path, the payload, and the SDK stay the same. A :agents turn runs inside your organization's sandbox: it can call tools, keep a workspace, store a durable conversation transcript, and issue a Telegram bot for that conversation.
Use https://api.netraruntime.com/v1 as the base URL, exactly as for inference. Only the model string changes. The extra capabilities are additive and namespaced: a netra object on responses, five netra.* stream events, a document library, conversation management, and an account endpoint. OpenAI request and response shapes, streaming frames, and SDK behaviour are unchanged.
| Need | Use |
|---|---|
| A one-shot answer executed with tools and files, no stored state | POST /v1/chat/completions with a :agents model. History stays in your request. |
| A durable run you can poll, resume, replay, cancel, or mirror to Telegram | POST /v1/responses with a :agents model and store: true (the default). |
| Plain inference with no sandbox | The same endpoints with a bare model ID. See Chat requests and Responses API. |
The organization is the boundary. One sandbox, one document library, and one set of limits belong to the organization, not to a key or a member. Every key in the organization reaches the same workspace and the same conversations, so use separate organizations when two workloads must not share state. The user request field is a label only: it scopes document listings and is kept for audit, but it never selects a workspace and never authorises anything.
Access and entitlement
Agents access is granted per organization on settled principal: an organization qualifies once its successful top-ups, net of refunds, reach USD 10 in lifetime settled payments. Grants, transfers, and wallet usage do not count.
Call GET https://api.netraruntime.com/v1/account before a run to read entitled, the current limits, usage, and workspace.can_run. When an organization is not entitled, reads keep working and writes or execution return 403 with code not_entitled and an upgrade_url. A refund that drops the organization below the threshold starts 30 days of read-only grace: existing conversations, documents, and responses stay readable, while new writes and runs are refused. Model discovery and the account endpoint stay available throughout.
An authenticated GET /v1/models lists the :agents variant of each model the caller can already see. If no :agents variant is listed, check entitled and the workspace's model access before changing code.
Quickstart
Create a stored response that executes in the sandbox and streams its events:
curl --fail-with-body -N https://api.netraruntime.com/v1/responses \
-H "Authorization: Bearer $NETRA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: report-2026-11-17" \
-d '{"model":"deepseek/deepseek-v4.1-flash:agents",
"input":"Summarise this week's sales from the files and write a short report.",
"tools":[{"type":"netra_tool","name":"files"},{"type":"netra_tool","name":"python"}],
"stream":true}'The same request through the OpenAI SDK. Only model and base_url differ from ordinary inference:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.netraruntime.com/v1",
api_key=os.environ["NETRA_API_KEY"],
max_retries=0,
)
response = client.responses.create(
model="deepseek/deepseek-v4.1-flash:agents",
input="Read notes.txt, then draft a one-page summary.",
tools=[{"type": "netra_tool", "name": "files"}],
)
print(response.output_text)
print(response.netra.conversation_id, response.netra.run_id)Re-call the same endpoint with the returned conversation to continue the thread, or fetch the stored response later. A stored response is a durable run: the HTTP call is a view, never the workload itself.
Model suffix
model | Behaviour |
|---|---|
deepseek/deepseek-v4.1-flash:agents | The turn runs in your organization's sandbox with tools, files, documents, and durable state. |
netra:agents | Same sandbox execution using the organization's default model. Use it when the exact model should follow the dashboard default. |
deepseek/deepseek-v4.1-flash | Plain stateless inference. No sandbox, no stored conversation, no netra object. |
Only the documented suffixes are accepted. An unknown suffix returns 400 with code invalid_model; a request is never silently downgraded to plain inference.
Endpoints
Everything except the extension rows is the OpenAI surface: same paths, same payloads, same streaming and re-attach formats. All calls use the same Netra API key with Authorization: Bearer.
| Path | Purpose |
|---|---|
GET /v1/models | Catalog, including the :agents variants you can run. |
POST /v1/chat/completions | One-shot turn in the sandbox. Nothing is stored. |
POST /v1/responses | Create a durable agentic run. |
GET /v1/responses/{id} | Stored snapshot, or the stream when stream=true. |
POST /v1/responses/{id}/cancel | Cancel a run that is still in flight. |
DELETE /v1/responses/{id} | Delete a stored response. |
GET /v1/responses/{id}/input_items | The input items the run consumed. |
GET /v1/conversations | List conversations (extension: OpenAI is id-only). |
POST /v1/conversations | Create a conversation before the first turn. |
GET · POST · DELETE /v1/conversations/{id} | Read, update metadata, or delete a conversation. |
GET · POST /v1/conversations/{id}/items | Read the transcript, or append items. |
GET · DELETE /v1/conversations/{id}/items/{item_id} | Read or delete one transcript item. |
POST · DELETE /v1/conversations/{id}/telegram | Re-issue the conversation's bot link, or detach the bot. |
POST · GET /v1/documents | Upload a document, or list and search the library. |
GET · PUT · DELETE /v1/documents/{doc} | Metadata, a new or restored version, or delete every version. |
GET /v1/documents/{doc}/content | Download the bytes of one version. |
GET /v1/account | Entitlement, limits, usage, and workspace state (extension). |
Durable runs and streaming
POST /v1/responses with a :agents model is durable. If the connection drops, the run continues; re-attach instead of re-sending. Every run is journalled with monotonic sequence_number values, which is what makes exact resume possible.
# resume exactly where the dropped stream stopped
curl -N "https://api.netraruntime.com/v1/responses/resp_01J...?stream=true&starting_after=41" \
-H "Authorization: Bearer $NETRA_API_KEY"Last-Event-IDis accepted as an alias ofstarting_after. Closing a stream cancels nothing.background: truereturns immediately withstatus: "queued"; poll or stream the response ID.- Deleting a transcript output item expires that response's event journal; later stream reads return
410. - A live response in the conversation blocks deletion of that response until it reaches a terminal state (
409). - A stored response is fetchable while its sandbox is suspended, because the snapshot never calls the model.
Idempotency
For stored Responses, an Idempotency-Key binds to one response for 24 hours, per organization. A matching retry returns that response's current snapshot. A still-running foreground response returns 409 idempotency_in_progress; a different request with the same key returns 409 idempotency_key_reused; a retry after deletion returns 404. One-shot Chat Completions has no re-attach or idempotent retry.
Stream events
Frames follow the OpenAI event contract: event: <type> plus a JSON body carrying type and sequence_number. Netra emits the lifecycle, item, text, reasoning-summary, and function-argument events it produces; other OpenAI event types are simply never sent. stream_options.include_obfuscation is accepted and ignored.
Five namespaced events are interleaved by default so the sandbox's own work is visible next to the answer:
| Event | Meaning |
|---|---|
netra.wake | The workspace is being prepared. Emitted while a stored run waits for its sandbox. |
netra.compaction | Model-facing context was compacted, with before and after token counts. |
netra.mirror | The turn was mirrored to a Telegram chat. |
netra.activity | A bounded, display-only preview of the sandbox's reasoning or one tool call. |
netra.draft | Model text as it arrives on a tool-bearing turn. The committed answer still arrives as response.output_text.*. |
A client that validates strictly against the OpenAI event union rejects unknown type values. Send "stream_options": {"netra_extensions": false} to opt out; those runs journal no extension events, so their sequence numbers are contiguous. Activity previews are best effort: each field is bounded and image payloads are redacted, so a lost preview never affects the answer, usage, or billing. Sandbox tool calls are not OpenAI function_call items and therefore never appear in output[].
Tools
Declare sandbox tools per request as {"type": "netra_tool", "name": "<tool>"} entries in tools. The list is not sticky: each request grants exactly what it declares. Read GET /v1/account limits.tools for what the deployment can currently execute; a declared tool outside that list is dropped from the run instead of failing it. The run reports what it had and used in netra.tools_enabled and netra.tools_used.
| Tool | What it does | Bounds |
|---|---|---|
files | Workspace file operations: list, stat, read, write, mkdir, move, delete. | Jailed to the conversation workspace; 64 KiB text per read or write. Materialised documents are read-only. |
python | Run a Python 3 snippet. | 64 KiB source, 30 s, 64 KiB output, memory capped. Requires files in the same request. |
bash | Run a shell snippet. | 64 KiB source, 30 s, 64 KiB output. Requires files in the same request. |
fetch | Retrieve one HTTPS URL through the egress proxy. | HTTPS 443 only, GET, up to 3 redirects, 32 KiB, 10 calls per response. |
web | search, extract, and screenshot against the content provider. | 10 operations per response; provider text clipped. |
browser | A live browser session: open, navigate, read, click, fill, evaluate, close. | One session per response, 60 s TTL, shares the 10-operation budget. Refusals (browser_capacity, browser_session_conflict) are answered as tool results. |
docs | Library operations: list, search, read, create, update, restore, delete, share, unshare. | Actor-scoped. Deleting a document tombstones it inside the actor's scope only. |
schedules | Recurring turns inside the conversation. | Needs store: true; 20 active per conversation; the scheduled tool list is explicit and may not include schedules or plugins. |
plugins | Call organization plugin bundles. | Needs store: true and an explicit bundle grant; inventory only when parameters is omitted; 10 operations per response. |
telegram and access | Manage the conversation's bot and its guests. | Conversation-scoped; destructive operations must echo the conversation or Telegram user ID. |
Working limits are read from GET /v1/account; the table states the current deployment's bounds, not a contractual promise. python or bash without files returns 400 invalid_tool_combination. Provider text is treated as untrusted input by the model, and the sandbox never holds the provider key.
Conversations and Telegram
A stored :agents response creates its conversation implicitly and returns netra.conversation_id with netra.run_id, netra.stream_url, and netra.telegram. Send "telegram": false to skip the bot, or create the conversation first when several runs must share one thread before the first turn lands.
Continue a thread with conversation, or with previous_response_id to build on the newest response of that conversation (a stale reference returns 409 stale_response). truncation defaults to auto, which compacts older context at the model window; disabled fails with 400 context_length_exceeded instead.
Conversations belong to the caller's organization. Another organization resolving the same conversation ID receives 404, never 403. Deletion is a fenced purge of the transcript and the sandbox thread; deleting a conversation or a sandbox never deletes the organization's documents.
Telegram. The bot link, claim URL, QR image, and expiry arrive in netra.telegram; re-issue it with POST /v1/conversations/{id}/telegram after expiry or to change the mirror mode, and stop mirroring with DELETE on the same path (the conversation is kept). Guests are granted, blocked, or revoked through the access tool. A guest allowed into a conversation gets the owner's full tool catalog, bounded by the access entry and the guest's daily allowance rather than by a smaller tool list. A Telegram chat receives the answer only, never the netra.* stream events.
Documents
The document library is durable and versioned, and it outlives the sandbox. Create a document with JSON (title and text) or multipart (file), then list or search with q, type, tag, and user filters.
Versions are append-only unless explicitly restored. PUT /v1/documents/{doc} requires If-Match with the version the change is based on; a mismatch returns 409 document_version_conflict. Send {"source_version": n} to restore an earlier version as a new one. GET /v1/documents/{doc}/content returns the bytes with an ETag and the version in X-Netra-Version.
Documents are conversation-scoped by default and become visible to the organization only after an explicit share. Organization storage is capped by the disk_bytes entitlement, currently 1 GiB per organization; exceeding it returns 409 disk_quota_exceeded. Usage is reported in GET /v1/account under usage.documents and usage.documents_bytes_used. Deleting a document removes every version; later reads of that document return 410.
Stored and ephemeral runs
Stored runs persist the transcript so you can poll, resume, and replay them. Set store: false for an ephemeral turn: no stored response, no conversation, and no Telegram bot, though tool execution and the stream are the same. schedules and plugins tools require store: true.
Client-owned function calls finish with status: "completed", the pending call IDs in netra.pending_calls, and the usual function_call_arguments.* events. Continue the run by appending function_call_output items to the conversation and sending the next turn. A workspace is suspended when idle and restored on the next turn, so treat wall-clock time between turns as unbounded and keep working files in the workspace or the library, not in memory.
Billing
Every generation is billed as inference usage to the calling key, at the rates of the model that produced it. Failed and cancelled runs settle the usage they already incurred, so a cancelled turn is never free and never double-charged. Preparing, waking, and idling a sandbox are platform costs and are not billed as tokens. Document storage counts against the organization quota described above rather than against token usage.
Use GET /v1/usage for the key's lifetime counters and GET /v1/account usage.responses_24h for recent agent activity. Responses carry standard usage details, including cached and reasoning tokens; do not add reasoning tokens again on top of output tokens.
Errors
Errors use the OpenAI envelope with a stable Netra code, so retry decisions can be made on the code rather than on the message text.
| Code | Status | Meaning |
|---|---|---|
not_entitled | 403 | The organization lacks Agents entitlement. Reads may still succeed during grace. |
invalid_model | 400 | Unknown model or unknown :agents suffix. |
invalid_tools · invalid_tool_combination | 400 | Malformed tool declaration, or python/bash without files. |
insufficient_quota | 402 | Prepaid balance cannot cover the generation. Top up and retry. |
stale_response · session_busy · session_deleted | 409 | The referenced response or conversation moved or was deleted; refetch before retrying. |
idempotency_in_progress · idempotency_key_reused | 409 | Same key, different state. Reuse the key only with the identical request. |
document_version_conflict · document_deleted · disk_quota_exceeded | 409 | Refetch the document version, restore a deleted one, or free quota. |
rate_limited · concurrency_limit | 429 | A rate window or the concurrent-response limit was hit. Honour Retry-After. |
no_ready_machine | 503 | No capacity. Nothing started and nothing was billed. Retry after Retry-After. |
wake_timeout | 503 | The workspace did not become ready in time. Retry after Retry-After. |
upstream_error | 5xx | The provider failed. Retry with the same Idempotency-Key for a stored run. |
Retries are safe only when they are idempotent. For stored Responses, retry with the same Idempotency-Key and request; for one-shot Chat Completions, decide whether a duplicate generation is acceptable before retrying. All other status handling matches Errors, limits, and retries.