Claude (Anthropic Protocol)
1. Overview
Claude is a large language model developed by Anthropic, possessing strong conversation and writing capabilities. It can understand context, generate coherent text, write code, and excels at logical reasoning and analysis. It emphasizes safety and ethical guidelines and will clearly identify itself as an AI assistant. It supports multilingual communication and can handle complex tasks and long conversations.
Compliance with Anthropic API
This API complies with the Anthropic Claude interface format specification and supports all official parameters.
Documentation Reference
This document lists only a subset of parameters. For a detailed list of parameters, please refer to the official documentation.
1.1 Supported model IDs
claude-opus-4-7claude-opus-4-6claude-opus-4-5claude-opus-4claude-sonnet-4-6claude-sonnet-4-5claude-sonnet-4claude-haiku-4-5
2. Request Instructions
Request Method:
POSTRequest URL:
https://api.exchangetoken.ai/v1/messages3. Request Parameters
3.1 Header Parameters
| Parameter Name | Type | Required | Description | Example |
|---|---|---|---|---|
Content-Type | string | Yes | Set request header type, must be application/json. | application/json |
Accept | string | Yes | Set response type, recommended to unify as application/json. | application/json |
x-api-key | string | Yes | API_KEY required for authentication, format: $YOUR_API_KEY. | $YOUR_API_KEY |
3.2 Body Parameters (application/json)
| Parameter Name | Type | Required | Description | Example |
|---|---|---|---|---|
model | string | Yes | The model ID to use. See the available versions listed in Overview, e.g., claude-opus-4-7. | claude-opus-4-7 |
messages | array | Yes | List of chat messages, compatible with Anthropic format. Each object in the array contains role and content. | [{"role": "user", "content": "Hello"}] |
message.role | string | Yes | Message role, optional values: user, assistant. | user |
message.content | string | Yes | The specific content of the message. | Hello, please tell me a joke. |
system | string | No | System prompt. | You are a friendly AI assistant. |
temperature | number | No | Sampling temperature, value 0~2. Higher values are more random; lower values are more concentrated and deterministic. | 0.7 |
top_p | number | No | Another way to adjust sampling distribution, value 0~1. Usually choose between this and temperature. | 0.9 |
stream | boolean | No | Whether to enable streaming output. When set to true, returns stream data similar to ChatGPT. | false |
max_tokens | integer | Yes | Maximum token count generated per response, limited by model context length. | 8192 |
Complete Code Examples
1. Basic Chat
bash
curl -X POST "https://api.exchangetoken.ai/v1/messages" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-7",
"system": [
{
"type": "text",
"text": "You are a friendly AI assistant"
}
],
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Hello, please give me a brief introduction to quantum mechanics"
}
]
}
],
"temperature": 0.7,
"max_tokens": 1000
}'python
import requests
import json
url = "https://api.exchangetoken.ai/v1/messages"
headers = {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"model": "claude-opus-4-7",
"system": [
{
"type": "text",
"text": "You are a friendly AI assistant"
}
],
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Hello, please give me a brief introduction to quantum mechanics"
}
]
}
],
"temperature": 0.7,
"max_tokens": 1000
}
response = requests.post(url, headers=headers, json=data)
print(response.json())2. Thinking Mode
bash
curl -X POST "https://api.exchangetoken.ai/v1/messages" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 2048,
"thinking": {
"type": "enabled",
"budget_tokens": 1024
},
"messages": [
{
"role": "user",
"content": "Explain how quantum entanglement works."
}
]
}'python
import requests
import json
url = "https://api.exchangetoken.ai/v1/messages"
headers = {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"model": "claude-sonnet-4-6",
"max_tokens": 2048,
"thinking": {
"type": "enabled",
"budget_tokens": 1024
},
"messages": [
{
"role": "user",
"content": "Explain how quantum entanglement works."
}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.json())3. Streaming Response
bash
curl -X POST "https://api.exchangetoken.ai/v1/messages" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-7",
"messages": [
{
"role": "user",
"content": "Tell me a short story"
}
],
"stream": true,
"max_tokens": 1024
}'python
import requests
import json
url = "https://api.exchangetoken.ai/v1/messages"
headers = {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"model": "claude-opus-4-7",
"messages": [
{
"role": "user",
"content": "Tell me a short story"
}
],
"stream": True,
"max_tokens": 1024
}
response = requests.post(url, headers=headers, json=data, stream=True)
for line in response.iter_lines():
if line:
print(line.decode('utf-8'))