Choose a model, enter your prompt, and see the result.
HiAPI Blog
HiAPI
Generate it with HiAPI
A working integration that calls Claude Opus 4.8 — the top-tier model in Anthropic's current Claude 4.8 lineup — through hiapi's OpenAI-compatible Chat Completions API. One request returns a real completion, plus the production patterns (streaming, tool calls, adaptive thinking) you'll need once the demo works.
Prerequisite: an hiapi API key. Grab one from the dashboard — it's a single sk-... string, and the same key works across every enabled model in your account, not just this one.
Everything below was run against the live API while writing this piece.
Claude Opus 4.8 is a text model on the standard Chat Completions endpoint — not the async /v1/tasks flow hiapi uses for image/video/audio models. One request, one response, no polling.
curl https://api.hiapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-<your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-8",
"messages": [
{"role": "user", "content": "Review this function for edge cases and suggest a fix."}
],
"max_tokens": 1024
}'
Response (trimmed):
{
"id": "msg_011CfFm8abLRcYtLVSky81As",
"model": "claude-opus-4-8",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "..." },
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 10, "completion_tokens": 4, "total_tokens": 14 }
}
Same call in Python, using only requests:
import requests
resp = requests.post(
"https://api.hiapi.ai/v1/chat/completions",
headers={"Authorization": "Bearer sk-<your-api-key>"},
json={
"model": "claude-opus-4-8",
"messages": [
{"role": "user", "content": "Review this function for edge cases and suggest a fix."}
],
"max_tokens": 1024,
},
timeout=60,
)
resp.raise_for_status()
data = resp.json()
print(data["choices"][0]["message"]["content"])
print(data["usage"]) # prompt_tokens / completion_tokens / total_tokens
Send the bare model ID claude-opus-4-8 — no provider prefix, no route suffix. hiapi lists this model with two backing routes (default and aws) for redundancy, but they share one model ID; you never pick between them.
Because the shape is OpenAI-compatible, this also works unmodified with the official openai Python/JS SDKs — just point base_url at https://api.hiapi.ai/v1 and pass your hiapi key.
Set "stream": true and read Server-Sent Events. Each chunk carries a delta.content fragment; the stream ends with finish_reason: "stop" on the final chunk followed by a [DONE] sentinel:
curl https://api.hiapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-<your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-8",
"messages": [{"role": "user", "content": "Count 1 to 3"}],
"stream": true,
"max_tokens": 20
}'
data: {"choices":[{"delta":{"content":"","role":"assistant"},"finish_reason":null,"index":0}]}
data: {"choices":[{"delta":{"content":"1"},"finish_reason":null,"index":0}]}
data: {"choices":[{"delta":{"content":", 2, 3"},"finish_reason":null,"index":0}]}
data: {"choices":[{"delta":{},"finish_reason":"stop","index":0}]}
data: [DONE]
Accumulate choices[0].delta.content across chunks to reconstruct the full text. The final data event (after finish_reason) carries the usage totals instead of a delta.
Declare functions the same way you would against OpenAI, then replay the assistant's tool_calls message plus a tool result message on the next turn:
curl https://api.hiapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-<your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-8",
"messages": [{"role": "user", "content": "What is the status of task demo-123?"}],
"max_tokens": 200,
"tools": [{
"type": "function",
"function": {
"name": "get_task_status",
"description": "Look up a task by ID.",
"parameters": {
"type": "object",
"properties": {"task_id": {"type": "string"}},
"required": ["task_id"],
"additionalProperties": false
}
}
}],
"tool_choice": "auto"
}'
The response comes back with finish_reason: "tool_calls" and the function name plus JSON-encoded arguments in choices[0].message.tool_calls. Run your function locally, then send the result back as a role: "tool" message carrying a matching tool_call_id in the next request — the model continues from there.
Claude Opus 4.8 supports an opt-in reasoning pass. Add "thinking": {"type": "adaptive"} and pick an effort level via output_config.effort (low, medium, or high are all confirmed working):
{
"model": "claude-opus-4-8",
"messages": [{"role": "user", "content": "Compare two approaches and state the trade-offs."}],
"thinking": {"type": "adaptive"},
"output_config": {"effort": "high"}
}
Two things worth knowing before you build around this. First, "adaptive" means the model decides on its own whether a prompt is worth thinking about — a trivial question at low or even medium effort can come back with no reasoning_details field at all, so don't assume every request produces one. Second, unlike some other text models on hiapi, Opus 4.8 doesn't return a human-readable trace: the reasoning_details array's reasoning.text entries come back empty, and only a signature entry is populated. Treat reasoning_details as opaque continuation state — pass it through unchanged if you carry the conversation into a follow-up tool call — not as something to parse or display to users.
Auth failures return HTTP 401 with a hiapi_error envelope:
{
"error": {
"code": "permission_denied",
"message": "This API key is invalid. Check that it is correct or use another API key and try again.",
"type": "hiapi_error"
}
}
Check response.status_code before touching response.json()["choices"], and log error.request_id if you need to escalate — support can trace a specific call from it.
Chat Completions calls aren't idempotent by request ID the way /v1/tasks jobs are — a retried request is a new completion, and a new bill. For production traffic, wrap calls in your own retry-with-backoff on 5xx/timeouts, and cap max_tokens so a retry storm (or an adaptive-thinking call that runs long) can't run up an unbounded cost.
Is claude-opus-4-8 the exact model ID I should send?
Yes — send the bare string claude-opus-4-8 in the model field. No provider-specific prefix and no route suffix needed; hiapi resolves it to the correct backing route internally.
Does this use the same /v1/tasks flow as hiapi's image and video models?
No. Text models like Claude Opus 4.8 use the synchronous POST /v1/chat/completions endpoint — one request, one response (or one SSE stream). /v1/tasks is only for media models (image, video, audio), which run async and return a URL to poll or a callback.
Can I use the OpenAI SDK instead of raw curl/requests?
Yes. Since the endpoint is OpenAI-compatible, point the official openai SDK's base_url at https://api.hiapi.ai/v1 and use your hiapi key as the api_key — no other code changes needed for basic chat, streaming, or tool calls.
Should I use Opus 4.8 or Sonnet 4.6? Opus 4.8 is the higher-capability, higher-cost tier — reach for it on harder reasoning, coding, or agentic tasks where accuracy matters more than latency or per-token cost. For high-volume or latency-sensitive traffic, Claude Sonnet 4.6 is the same API shape at a lower price point.
Will thinking always return a visible reasoning trace?
No, on both counts: adaptive thinking may skip reasoning entirely for a request it judges simple, and when it does think, Opus 4.8's reasoning_details currently comes back with an empty text field — only the signature is populated. Don't build a UI that assumes a readable trace is always present.
Where do I check current pricing before running a large batch? hiapi's pricing page lists live per-token rates for Claude Opus 4.8 — check it before budgeting, since this article doesn't hardcode a number that could go stale.