Skip to content

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-7
  • claude-opus-4-6
  • claude-opus-4-5
  • claude-opus-4
  • claude-sonnet-4-6
  • claude-sonnet-4-5
  • claude-sonnet-4
  • claude-haiku-4-5

2. Request Instructions

Request Method:

POST

Request URL:

https://api.exchangetoken.ai/v1/messages

3. Request Parameters

3.1 Header Parameters

Parameter NameTypeRequiredDescriptionExample
Content-TypestringYesSet request header type, must be application/json.application/json
AcceptstringYesSet response type, recommended to unify as application/json.application/json
x-api-keystringYesAPI_KEY required for authentication, format: $YOUR_API_KEY.$YOUR_API_KEY

3.2 Body Parameters (application/json)

Parameter NameTypeRequiredDescriptionExample
modelstringYesThe model ID to use. See the available versions listed in Overview, e.g., claude-opus-4-7.claude-opus-4-7
messagesarrayYesList of chat messages, compatible with Anthropic format. Each object in the array contains role and content.[{"role": "user", "content": "Hello"}]
  message.rolestringYesMessage role, optional values: user, assistant.user
  message.contentstringYesThe specific content of the message.Hello, please tell me a joke.
systemstringNoSystem prompt.You are a friendly AI assistant.
temperaturenumberNoSampling temperature, value 0~2. Higher values are more random; lower values are more concentrated and deterministic.0.7
top_pnumberNoAnother way to adjust sampling distribution, value 0~1. Usually choose between this and temperature.0.9
streambooleanNoWhether to enable streaming output. When set to true, returns stream data similar to ChatGPT.false
max_tokensintegerYesMaximum 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'))