Create an Anthropic-compatible message
Endpoint Examples
Messages
Accepts Anthropic Messages requests, including video blocks for models that advertise video input.
POST
Create an Anthropic-compatible message
/v1/messages accepts compressed request bodies (Content-Encoding: gzip, deflate, or br) on authenticated JSON requests — useful for long conversations, where compressed uploads cut time-to-first-token. See Compressed Request Bodies.Overview
The/v1/messages endpoint provides full Anthropic API compatibility. Clients using the Anthropic SDK can use NanoGPT by simply changing the base URL — no code changes required.
NanoGPT accepts requests in the Anthropic Messages format, routes them to the requested NanoGPT model, and returns responses back in the Anthropic Messages shape.
For non‑Anthropic models, NanoGPT transparently translates the request to an OpenAI-style chat format internally and then converts the response back to Anthropic Messages format.
This endpoint supports:
- Text generation (streaming and non-streaming)
- Multi-turn conversations
- Tool use (function calling)
- Vision (images), video understanding, and document/PDF processing
- Extended thinking (reasoning models)
- Prompt caching
- Token estimates via
POST /api/v1/messages/count_tokens
Endpoint
Authentication
Use either header:Authorization: Bearer YOUR_API_KEYx-api-key: YOUR_API_KEY
Request Format
Required Fields
Optional Fields
Message Format
Messages must have arole (user or assistant) and content:
Content Block Types
Text Block
Image Block (for vision-capable models)
image/jpeg, image/png, image/gif, image/webp
Document Block (for PDF-capable models)
Video Block (for video-capable models)
Usetype: "video" for new integrations. Inline video bytes use an Anthropic base64 source:
document compatibility block with a video/* source is normalized as video. A document with application/pdf remains a document. Public remote sources must use HTTPS; inline base64 must be valid. See the Video Input guide for model discovery, limits, errors, segment behavior, and the equivalent Chat Completions and Responses shapes.
Tool Use Block (in assistant messages)
Tool Result Block (in user messages)
Tool Definitions
Tool Choice Options
Extended Thinking
For models that support extended thinking (reasoning):budget_tokensmust be >= 1024budget_tokensmust be <max_tokens- Model must support thinking for the exact model ID you send (check
GET /api/v1/models)
:thinking is model-specific and only works when that exact ID (or a documented alias) exists.
-thinking is a legacy alias pattern for some model families only, not universal.
Do not assume -thinking works for arbitrary model IDs. Always check GET /api/v1/models for exact valid IDs.
If the requested model does not support thinking, NanoGPT automatically ignores/strips the thinking parameter and routes the request to the base model.
For Chat Completions compatibility controls, :reasoning-exclude (or reasoning.exclude) only hides reasoning output; it does not force reasoning compute off. Use reasoning_effort / reasoning.effort to control reasoning depth, and set none to disable reasoning behavior.
Response Format
Non-Streaming Response
Stop Reasons
Streaming Response (SSE)
See also: Streaming Protocol (SSE). Whenstream: true, the response is Server-Sent Events with named event types:
Event: message_start
Event: content_block_start
Event: content_block_delta
Event: content_block_stop
Event: message_delta
Event: message_stop
Streaming Tool Use
When the model uses tools during streaming:Supported Models
Claude Models (Full Support)
*Use only exact thinking-capable model IDs from
GET /api/v1/models.
Other Models (Via Compatibility Layer)
The v1/messages endpoint also works with non-Anthropic models:
See the Models documentation for the full list.
Prompt Caching
For the full guide (supported models, thresholds, pricing, and usage fields), see Prompt Caching. NanoGPT automatically applies implicit caching on providers/models that support it (including OpenAI, Gemini, and many open-source provider/model routes), with no extra request flags. Use explicit prompt-caching controls on Claude when you need deterministic cache boundaries, TTL selection, orstickyProvider consistency control.
Enable via Header
TTL Options
- Default: 5-minute cache TTL
- Extended: Add
extended-cache-ttl-2025-04-11to request 1-hour TTL on Anthropic-native Claude flows
Cache Control in Content (Explicit Claude Controls)
Addcache_control to content blocks for explicit Claude caching:
Cache Usage in Response
Error Handling
For a general guide across NanoGPT APIs, see Error Handling.Error Response Format
Error Types
All error responses include an
X-Request-ID header for support requests.
Headers
Request Headers
*One of
Authorization or x-api-key is required.
BYOK Headers
For Bring Your Own Key:Examples
Basic Request (cURL)
Streaming Request (cURL)
With Tools (cURL)
Anthropic SDK (Node.js)
Anthropic SDK with Streaming (Node.js)
Anthropic SDK with Prompt Caching (Node.js)
Vision Example (Node.js)
Python SDK
Limits
Limitations
- GPU-TEE models do not support streaming through
POST /api/v1/messages. UsePOST /api/v1/chat/completionsif you need streaming with GPU-TEE models.
Migration from Anthropic
To migrate from Anthropic’s API to NanoGPT:-
Change the base URL:
- From:
https://api.anthropic.com - To:
https://nano-gpt.com/api
https://nano-gpt.com/api/v1/messages - From:
- Use your NanoGPT API key instead of your Anthropic key
- No other code changes required — the API is fully compatible
Service tier compatibility
Anthropic-style service tiers are normalized when routing to providers that support service tiers:standard→defaultdefault→defaultflex→flexpriority→prioritybatch→ ignored for service-tier routing
Notes
- The
anthropic-versionheader is accepted but not required - Token usage numbers use NanoGPT’s token accounting (may differ slightly from Anthropic’s exact counts)
- All Anthropic SDK features are supported, including streaming, tools, and caching