Anthropic-format API
Flash API exposes an endpoint that is fully compatible with the Anthropic Messages API and tuned for the Claude family. If you use the official Anthropic SDK, change base_url and you're done.
Endpoint
For the official Anthropic Python / Node.js SDK, the Base URL must not include /v1:
https://ai.flashapi.topThe official SDK appends /v1/messages. Including /v1 in the Base URL produces the incorrect /v1/v1/messages path. With cURL, the full request URL is still https://ai.flashapi.top/v1/messages.
OpenCode uses
@ai-sdk/anthropic, not the official SDK. ItsbaseURLmust include/v1; do not mix these configurations.
Authentication
Two options:
Option 1: x-api-key (recommended)
x-api-key: YOUR_API_KEYOption 2: Authorization
Authorization: Bearer YOUR_API_KEYMessages API
Overview
Claude's core conversation endpoint.
Endpoint
POST /v1/messagesRequest example
curl https://ai.flashapi.top/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Write a binary search in Python"
}
]
}'Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model name |
| messages | array | Yes | List of conversation messages |
| max_tokens | integer | Yes | Maximum number of tokens to generate |
| system | string | No | System prompt |
| temperature | number | No | Sampling temperature, 0–1 |
| top_p | number | No | Nucleus sampling |
| stream | boolean | No | Whether to stream the output |
| stop_sequences | array | No | Stop sequences |
Messages format
Unlike OpenAI, Anthropic takes the system prompt as a separate parameter:
{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"system": "You are a Python expert",
"messages": [
{
"role": "user",
"content": "Write a quicksort"
},
{
"role": "assistant",
"content": "Sure, here's a quicksort in Python..."
},
{
"role": "user",
"content": "Add detailed comments"
}
]
}Note:
messagescan only contain theuserandassistantroles- The first message must be from
user - Keep messages in conversation order; consecutive messages with the same role are combined into one turn, so strict alternation is not required
Response format
{
"id": "msg_123",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "This is Claude's reply"
}
],
"model": "claude-opus-5-5",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 25,
"output_tokens": 150
}
}Streaming
Set stream: true to turn it on:
curl https://ai.flashapi.top/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hi"}],
"stream": true
}'Streaming events:
event: message_start
data: {"type":"message_start","message":{"id":"msg_123",...}}
event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"Hi"}}
event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":" there"}}
event: message_stop
data: {"type":"message_stop"}Supported models
| Recommended model | Description | Context |
|---|---|---|
| claude-opus-5-5 | Current recommended high-performance model | 1M |
Examples use claude-opus-5-5. Check GET /v1/models with your group's key and the console for available models. Maximum output depends on the model and channel; context length is not the maximum output length.
Multimodal input
Claude accepts image input:
Image format
{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": "/9j/4AAQSkZJRg..."
}
},
{
"type": "text",
"text": "What's in this image?"
}
]
}
]
}Supported image formats:
- JPEG
- PNG
- GIF
- WebP
Maximum image size: 5 MB
Code examples
Python (official SDK)
from anthropic import Anthropic
client = Anthropic(
api_key="YOUR_API_KEY",
base_url="https://ai.flashapi.top"
)
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{"role": "user", "content": "Write a Python decorator"}
]
)
print(message.content[0].text)Python (streaming)
with client.messages.stream(
model="claude-opus-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Write an article"}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)Node.js (official SDK)
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://ai.flashapi.top'
});
const message = await client.messages.create({
model: 'claude-opus-5-5',
max_tokens: 1024,
messages: [
{ role: 'user', content: 'Write a quicksort' }
]
});
console.log(message.content[0].text);cURL
curl https://ai.flashapi.top/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello, Claude!"}
]
}'Error handling
Error response format
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Error description"
}
}Common error types
| Error type | Description |
|---|---|
| invalid_request_error | Invalid request parameters |
| authentication_error | Authentication failed |
| permission_error | Insufficient permissions |
| not_found_error | Resource not found |
| rate_limit_error | Rate limited |
| api_error | Internal API error |
| overloaded_error | Service overloaded |
Error handling example
from anthropic import Anthropic, APIConnectionError, APIStatusError, APIError
client = Anthropic(
api_key="YOUR_API_KEY",
base_url="https://ai.flashapi.top"
)
try:
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}]
)
except APIConnectionError as e:
print(f"Connection failed: {e}")
except APIStatusError as e:
print(f"HTTP status: {e.status_code}")
print(f"Error response: {e.body}")
except APIError as e:
print(f"API error: {e}")Advanced features
1. System prompt
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
system="You are a Python expert who specializes in data analysis and machine learning.",
messages=[
{"role": "user", "content": "How do I handle missing values in pandas?"}
]
)2. Multi-turn conversations
conversation = [
{"role": "user", "content": "Write a user class"},
{"role": "assistant", "content": "Sure, here's a User class..."},
{"role": "user", "content": "Add password hashing"}
]
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=conversation
)3. Image analysis
import base64
with open("image.jpg", "rb") as f:
image_data = base64.b64encode(f.read()).decode()
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": image_data
}
},
{
"type": "text",
"text": "Analyze this architecture diagram"
}
]
}
]
)Best practices
1. Set max_tokens deliberately
Set max_tokens for the task, within the output limit of the selected model and channel. The recommended Claude model has a 1M context window; this does not mean a single response can generate 1M tokens.
2. Use the system prompt
Put role instructions in the system parameter, not in messages:
# ✅ Recommended
system="You are a Python expert"
messages=[{"role": "user", "content": "Write some code"}]
# ❌ Not recommended
messages=[
{"role": "user", "content": "You are a Python expert. Write some code"}
]3. Handle long conversations
The recommended Claude model has a 1M context window, but you should still:
- Summarize the conversation periodically
- Drop unimportant history
- Use caching (where supported)
4. Retry on errors
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(
stop=stop_after_attempt(3),
wait=wait_exponential(multiplier=1, min=4, max=10)
)
def call_claude():
return client.messages.create(...)Compared with the OpenAI format
| Feature | Anthropic format | OpenAI format |
|---|---|---|
| System prompt | Separate parameter | Inside messages |
| Roles | user/assistant | system/user/assistant |
| Required parameters | model, messages, max_tokens | model, messages (Chat Completions) |
| Image input | Native | Some models |
| Streaming | SSE events | SSE data stream |
Next steps
- OpenAI-format API: the general-purpose format
- Pricing: what it costs
- Get help: when something breaks