API reference
Chat completions, streaming and caching.
Send standard OpenAI chat-completion requests to POST https://api.arnict.com/v1/chat/completions. List the models your key can call with GET /v1/models.
Request structure
| Field | Type | Required | Notes |
|---|---|---|---|
model |
string |
Yes | Exact online model ID from /models or GET /v1/models. |
messages |
array |
Yes | Ordered list of { role, content } objects (system, user, assistant, tool). |
stream |
boolean |
No | Defaults to false. Set true for Server-Sent Events (SSE). |
stream_options |
object |
No | Pass {"include_usage": true} alongside stream: true to receive final token counts in the closing chunk. |
max_tokens |
integer |
No | Maximum completion tokens to generate, bounded by the model's output limit on /models. |
temperature |
number |
No | Sampling temperature (typically 0.0 to 2.0). |
top_p |
number |
No | Nucleus sampling cutoff (0.0 to 1.0). |
stop |
string | string[] |
No | One or more stop sequences. |
tools / tool_choice |
array | string |
No | Function-calling tool definitions supported by the selected model. |
Streaming (SSE)
Set stream: true and stream_options: {"include_usage": true} to stream incremental deltas over text/event-stream and capture exact token accounting on completion:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.arnict.com/v1",
api_key=os.environ["ARNICT_API_KEY"],
)
stream = client.chat.completions.create(
model="zai/glm-5.3-flash-abliterated",
messages=[{"role": "user", "content": "Explain TCP slow start in three bullet points."}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.usage:
print("\nUsage:", chunk.usage)
Each response includes an X-Request-ID header. Record X-Request-ID in your application logs so any failed or slow request can be traced in Dashboard Usage without storing or emailing prompt text.
Prompt caching
Prompt caching is automatic. When requests share an identical leading prefix (a stable system prompt, shared repository files, a long conversation history), the repeated part can be served from a temporary cache and billed at the cached-input rate. Hits depend on your traffic and are not guaranteed.
How cached tokens are billed
Arnict prices uncached input, cached input, and output tokens separately:
- Total prompt tokens are reported in
usage.prompt_tokens. - Tokens served from cache are reported in
usage.prompt_tokens_details.cached_tokens. - Cached tokens are subtracted from total input tokens before applying the uncached input rate:
billable_uncached_input = prompt_tokens - cached_tokens
request_cost = (billable_uncached_input * input_rate
+ cached_tokens * cached_input_rate
+ completion_tokens * output_rate) / 1_000_000
Practical prefix hygiene
- Keep static instructions, tool schemas, and unchanging reference context at the very beginning of
messages. - Place per-request timestamps, user IDs, or volatile snippets after the shared prefix so they do not invalidate the cache boundary.
- Check your cached-input share and its effect on spend in Dashboard Usage, and model it with the estimator.
Interrupted streams
If a client disconnects mid-stream or a stream terminates after generating confirmed tokens, billing applies only to confirmed usage recorded by the serving path. Where a terminal usage receipt is missing, records are reviewed before applying a charge.