Skip to content

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.top

The 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. Its baseURL must include /v1; do not mix these configurations.

Authentication ​

Two options:

http
x-api-key: YOUR_API_KEY

Option 2: Authorization ​

http
Authorization: Bearer YOUR_API_KEY

Messages API ​

Overview ​

Claude's core conversation endpoint.

Endpoint ​

POST /v1/messages

Request example ​

bash
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 ​

ParameterTypeRequiredDescription
modelstringYesModel name
messagesarrayYesList of conversation messages
max_tokensintegerYesMaximum number of tokens to generate
systemstringNoSystem prompt
temperaturenumberNoSampling temperature, 0–1
top_pnumberNoNucleus sampling
streambooleanNoWhether to stream the output
stop_sequencesarrayNoStop sequences

Messages format ​

Unlike OpenAI, Anthropic takes the system prompt as a separate parameter:

json
{
  "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:

  • messages can only contain the user and assistant roles
  • 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 ​

json
{
  "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:

bash
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 modelDescriptionContext
claude-opus-5-5Current recommended high-performance model1M

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 ​

json
{
  "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) ​

python
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) ​

python
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) ​

javascript
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 ​

bash
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 ​

json
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "Error description"
  }
}

Common error types ​

Error typeDescription
invalid_request_errorInvalid request parameters
authentication_errorAuthentication failed
permission_errorInsufficient permissions
not_found_errorResource not found
rate_limit_errorRate limited
api_errorInternal API error
overloaded_errorService overloaded

Error handling example ​

python
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 ​

python
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 ​

python
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 ​

python
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:

python
# ✅ 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 ​

python
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 ​

FeatureAnthropic formatOpenAI format
System promptSeparate parameterInside messages
Rolesuser/assistantsystem/user/assistant
Required parametersmodel, messages, max_tokensmodel, messages (Chat Completions)
Image inputNativeSome models
StreamingSSE eventsSSE data stream

Next steps ​

One base URL for GPT, Claude and Gemini