Messages API (Anthropic)
Use the Anthropic Messages API at POST /v1/messages with the Anthropic SDK or Claude Code. Sampling params, tools, images, thinking, prompt caching, and streaming.
Use this page with an AI assistant
Opens a new chat with this docs URL and the correct AICredits base URLs.
POST https://api.aicredits.in/v1/messages accepts requests in the Anthropic Messages API format. Point the Anthropic SDK, Claude Code, or any Anthropic-compatible client at AICredits and keep your existing code.
Setup
Use the bare base URL https://api.aicredits.in (without /v1). Anthropic SDKs append /v1/messages themselves.
curl https://api.aicredits.in/v1/messages \
-H "Authorization: Bearer sk-your-key-here" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4.6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello!"}]
}'import anthropic
client = anthropic.Anthropic(
base_url="https://api.aicredits.in",
auth_token="sk-your-key-here", # sent as a Bearer token
)
message = client.messages.create(
model="anthropic/claude-sonnet-4.6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
print(message.content[0].text)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.aicredits.in",
authToken: "sk-your-key-here", // sent as a Bearer token
});
const message = await client.messages.create({
model: "anthropic/claude-sonnet-4.6",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }],
});
console.log(message.content);export ANTHROPIC_BASE_URL=https://api.aicredits.in
export ANTHROPIC_AUTH_TOKEN=sk-your-key-here
claudeSee the Claude Code guide for full setup.
Authentication is a standard Authorization: Bearer sk-... header with your AICredits API key.
Which models work
- Claude models are forwarded to Anthropic in native format when possible, so every Anthropic parameter reaches the model unchanged.
- Any other model on the platform also works. The request is converted to chat format internally, routed and billed like any other request, and the answer is converted back to Anthropic format. This lets you drive models from other providers with the Anthropic SDK.
Guardrails and native format
When guardrails (such as PII masking) are enabled, requests are always converted instead of forwarded natively so the guardrails can apply. The features below are supported on both paths unless noted.
The anthropic/ model prefix is optional for Claude models.
Request fields
| Field | Notes |
|---|---|
model | Required. Any AICredits model ID. |
max_tokens | Defaults to 4096 if omitted or 0. |
messages | user / assistant messages. content is a string or an array of content blocks. |
system | A string, or an array of text blocks (blocks may carry cache_control). |
temperature, top_p, top_k | Carried through. An explicit 0 is honored. |
stop_sequences | Carried through. |
metadata | Carried through; metadata.user_id is also used as the end-user identifier. |
stream | true for server-sent events. |
tools, tool_choice | Custom tools with input_schema. See below. |
thinking | Extended thinking. See below. |
Content blocks
Supported in messages[].content:
textimagewith abase64orurlsourcetool_useandtool_result(the resultcontentmay be text plus images;is_error: trueis preserved)thinkingandredacted_thinking(send them back unchanged on follow-up turns)
Tools and tool_choice
Define tools with name, description, and input_schema.
tool_choice | Behavior |
|---|---|
{"type": "auto"} | Model decides |
{"type": "any"} | Model must call some tool |
{"type": "tool", "name": "..."} | Model must call that tool |
{"type": "none"} | No tool calls |
disable_parallel_tool_use: true | One tool call at a time |
Forced tool use disables thinking
Anthropic does not allow extended thinking together with a forced tool choice (any or tool). On Claude models AICredits drops thinking when the request forces a tool.
message = client.messages.create(
model="anthropic/claude-sonnet-4.6",
max_tokens=1024,
tools=[{
"name": "get_weather",
"description": "Get the weather for a city",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}],
tool_choice={"type": "auto"},
messages=[{"role": "user", "content": "Weather in Mumbai?"}],
)Only custom (client-defined) tools are converted for non-Claude models.
Images
{
"role": "user",
"content": [
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "iVBOR..."}},
{"type": "text", "text": "What is in this image?"}
]
}A {"type": "url", "url": "https://..."} source also works. The model must support image input.
Extended thinking
Pass thinking: {"type": "enabled", "budget_tokens": 4096} on a model that supports it.
- On Claude models the exact config is forwarded.
budget_tokensmust be belowmax_tokens; if you leavemax_tokensunset it is raised to leave room for the answer, and otherwise the budget is reduced to fit. If there is no room for the minimum budget (1024), thinking is dropped.temperatureandtop_pare dropped when thinking is on, as Anthropic requires. - On other reasoning models the budget is mapped to a reasoning effort: up to 2048 tokens is
low, up to 10000 ismedium, above that ishigh.
On the native path the response contains thinking blocks with signatures as Anthropic returns them. On the converted path the response contains text and tool_use blocks only.
Prompt caching
Add cache_control to system blocks, tool definitions, or message content blocks, exactly as with Anthropic:
{
"system": [
{"type": "text", "text": "<long instructions>", "cache_control": {"type": "ephemeral", "ttl": "1h"}}
]
}ttlmay be"5m"(default) or"1h".- Anthropic allows at most 4 cache breakpoints per request. When a converted request carries more, the extras are dropped.
- Cache writes and reads are billed at the Claude rates described in Prompt Caching.
Streaming
Set stream: true to receive Anthropic-style server-sent events: message_start, content_block_start, content_block_delta (text_delta, input_json_delta), content_block_stop, message_delta, message_stop, and periodic ping events to keep idle connections open.
with client.messages.stream(
model="anthropic/claude-sonnet-4.6",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a haiku."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)Response and usage
The response is a standard Anthropic message object with content, stop_reason, and usage (input_tokens, output_tokens). On the converted path, stop_reason is end_turn, max_tokens, or tool_use, and non-streaming usage also includes AICredits' cost (INR), latency_ms, and cost_details fields. Billing is identical to /v1/chat/completions: provider cost converted to INR plus your markup, deducted from your wallet.
Errors use Anthropic's error envelope ({"type": "error", "error": {...}}), so the Anthropic SDKs raise their usual exceptions. See Errors.
Limits
- Request body: 10 MB maximum.
- Rate limits and concurrency follow your plan. See Rate Limits.
- Document (PDF) blocks and other Anthropic-only parameters are forwarded on the native Claude path only; the converted path for other models handles the blocks listed above.