HiAPI
  • Models
  • Pricing
Search

Search HiAPI models, tools, and resources.

  • Models
  • Pricing
HiAPI

One API, All AI Models

Generate images, video, and audio with leading models through one production-ready API.

Get a free API key

AI Image API

  • All image models
  • GPT Image 2.5 Flare
  • GPT Image 2.5 Sunburst
  • GPT Image 2
  • Nano Banana 2
  • Seedream 5.0 Pro
  • Qwen Image 2.0 Pro
  • FLUX 1.1 Pro

AI Video API

  • All video models
  • Seedance 2.5
  • FLUX.3 Video
  • Seedance 2.0
  • Veo 3.1
  • Kling 3.0 Omni

AI Audio API

  • All audio models
  • MiniMax Music 2.6
  • MiniMax Music 1.5
  • ElevenLabs v3
  • Text to music
  • Text to speech

Product

  • Model marketplace
  • Playground
  • Pricing
  • Image API Cost Calculator
  • Free GPT Image 2 Generator
  • Free Background Remover
  • Free Nano Banana Image Generator
  • Outfit Preview
  • Product Photo Lab

Developers

  • Agent setup
  • Documentation
  • API Reference
  • Agent Skills
  • LLM integration index
  • Blog

Company

  • About
  • Contact support
  • Terms of Service
  • Privacy Policy

© 2026 hiapi. All rights reserved.

Open source on GitHubPython SDK on PyPI
  • What you'll build
  • Minimal runnable example
  • Production patterns
  • Streaming
  • Tool calls
  • Adaptive thinking
  • Error handling
  • Idempotency and retries
  • Related reading
  • FAQ
TutorialSep 17, 2026

How to Use Claude Sonnet 4.6 via the hiapi API

hiapiClaude Sonnet 4.6Chat Completions APIAPI TutorialAnthropic

Latest models

Explore models

Contents
  • What you'll build
  • Minimal runnable example
  • Production patterns
  • Streaming
  • Tool calls
  • Adaptive thinking
  • Error handling
  • Idempotency and retries
  • Related reading
  • FAQ

Generate it with HiAPI

Choose a model, enter your prompt, and see the result.

HiAPI Blog

Related articles

HiAPI

Generate it with HiAPI

What you'll build

A working integration that calls Claude Sonnet 4.6 through hiapi's OpenAI-compatible Chat Completions API — a single request that returns a real completion, plus the production patterns (streaming, tool calls, adaptive thinking) you'll actually use 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.

Minimal runnable example

Claude Sonnet 4.6 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-sonnet-4-6",
    "messages": [
      {"role": "user", "content": "Explain how an HTTP cache works in three short paragraphs."}
    ]
  }'

Response (trimmed):

{
  "id": "msg_bdrk_011Cf8Bo25qCVFFQF5ETk8Wf",
  "model": "claude-sonnet-4-6",
  "object": "chat.completion",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "..." },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 13, "completion_tokens": 4, "total_tokens": 17 }
}

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-sonnet-4-6",
        "messages": [
            {"role": "user", "content": "Explain how an HTTP cache works in three short paragraphs."}
        ],
    },
    timeout=60,
)
resp.raise_for_status()
data = resp.json()
print(data["choices"][0]["message"]["content"])
print(data["usage"])  # prompt_tokens / completion_tokens / total_tokens

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.

Production patterns

Streaming

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-sonnet-4-6",
    "messages": [{"role": "user", "content": "Count 1 to 3"}],
    "stream": true
  }'
data: {"choices":[{"delta":{"content":"","role":"assistant"},"finish_reason":null,"index":0}]}

data: {"choices":[{"delta":{"content":"Here"},"finish_reason":null,"index":0}]}

data: {"choices":[{"delta":{"content":" you"},"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.

Tool calls

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-sonnet-4-6",
    "messages": [{"role": "user", "content": "What is the status of task demo-123?"}],
    "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 returns finish_reason: "tool_calls" with the function name and JSON-encoded arguments in choices[0].message.tool_calls. Run your function locally, then send the result back as a role: "tool" message with a matching tool_call_id in the next request — the model continues from there.

Adaptive thinking

Claude Sonnet 4.6 supports an opt-in reasoning pass. Add "thinking": {"type": "adaptive"} and pick an effort level (low, medium, high, or max) via output_config.effort:

{
  "model": "claude-sonnet-4-6",
  "messages": [{"role": "user", "content": "Compare two approaches and state the trade-offs."}],
  "thinking": {"type": "adaptive"},
  "output_config": {"effort": "high"}
}

The readable reasoning trace comes back in choices[0].message.reasoning_content; the raw reasoning_details array carries signature metadata you must preserve unchanged if you continue the conversation into a tool call — don't parse, display, or invent it, just pass it straight through on the next request.

Error handling

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.

Idempotency and retries

Chat Completions calls aren't idempotent by request ID the way /v1/tasks jobs are — a retried request is a new completion. For production traffic, wrap calls in your own retry-with-backoff on 5xx/timeouts, and cap max_tokens so a retry storm can't run up an unbounded bill.

Related reading

  • Claude Sonnet 4.6 model reference — full parameter table, response schema, and more request examples straight from hiapi's docs.
  • Authentication — how hiapi API keys work and how to rotate them.
  • hiapi pricing — live per-token rates for Claude Sonnet 4.6 and every other enabled model.

FAQ

Is claude-sonnet-4-6 the exact model ID I should send? Yes — send the bare string claude-sonnet-4-6 in the model field. hiapi routes it through Anthropic's Claude Sonnet 4.6 behind an OpenAI-compatible interface, so no provider-specific prefix is needed.

Does this use the same /v1/tasks flow as hiapi's image and video models? No. Text models like Claude Sonnet 4.6 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.

Does Claude Sonnet 4.6 support image input? Yes, via content blocks — set a message's content to an array containing a block with type: "image_url" and image_url.url pointing at a public image URL, alongside your text block.

What happens if I omit thinking? Adaptive thinking is opt-in per the current release — omit the thinking field (or set thinking.type to disabled) and the model answers directly with no reasoning_content in the response.

Where do I check current pricing before running a large batch? hiapi's pricing page lists live per-token rates for Claude Sonnet 4.6 — check it before budgeting, since rates can change and this article doesn't hardcode a number that could go stale.

Latest models

View all models
  • GPT Image 2.5 FlareFrom $0.050/image
  • GPT Image 2.5 SunburstFrom $0.050/image
  • GPT Image 2From $0.030/image
  • Nano Banana 2From $0.051/image

Explore models

TextImageVideoAudio
Back to blog
GPT Image 2.5 FlareFrom $0.050/image
GPT Image 2.5 SunburstFrom $0.050/image
GPT Image 2From $0.030/image
Nano Banana 2From $0.051/image
View all models
TextChat and reasoning
ImageGenerate and edit
VideoText and image to video
AudioSpeech and music
Start generating
View model pricing
View all articles
How to Use glm-5.3 via the hiapi API: curl, Python, and a Working Request

How to Use glm-5.3 via the hiapi API: curl, Python, and a Working Request

How to Use kimi-k3 via the hiapi API: curl, Python, and a Working Request

How to Use kimi-k3 via the hiapi API: curl, Python, and a Working Request

How to Use lyria-3.5 via the hiapi API: curl, Python, and a Working Request

How to Use lyria-3.5 via the hiapi API: curl, Python, and a Working Request

Multi-Angle Image-to-Video Prompting with minimax-h3-max via the hiapi API

Multi-Angle Image-to-Video Prompting with minimax-h3-max via the hiapi API

GPT Image 2.5 Sunburst Text-to-Image API: A Working curl and Python Guide

GPT Image 2.5 Sunburst Text-to-Image API: A Working curl and Python Guide

How to Use gpt-image-2.5-flare@pro via the hiapi API: curl, Python, and a Working Request

How to Use gpt-image-2.5-flare@pro via the hiapi API: curl, Python, and a Working Request

Start generating