Claude API Access Guide: Native Anthropic Interface and Key Configuration

  • 发布时间
  • 语言en

Access Anthropic Claude models via the AzzTimes gateway: learn about endpoints, authentication, cURL examples, request/response fields, SSE streaming, and common error codes.

1. Overview

AzzTimes provides a proxy gateway compatible with the Anthropic Messages API (/v1/messages) for developers. Simply point your requests to our gateway and replace your authentication key with the sk- key generated in the "User Center - API Keys" section to start using Claude models directly, without changing your existing code.

The currently available models are listed in the Model Square (e.g., claude-sonnet-5, claude-opus-5, claude-sonnet-4-6, claude-opus-4-8, etc.). The complete list and unit pricing can be queried at any time via GET /v1/models.

2. API Endpoints

MethodPathDescription
POST/v1/messagesProxy forwarding entrance; request body follows Anthropic /v1/messages payload structure
GET/v1/modelsList of models and unit prices (no authentication required)

Gateway address: https://www.relay-api.com. Follow the table above for request paths.

3. Authentication

Generate a key in "User Center → API Keys" in the format sk-xxxxxxxx. Include it in your requests using one of the following methods:

  • Authorization Header: Authorization: Bearer sk-your-key (Recommended, compatible with most SDKs)
  • x-api-key Header: x-api-key: sk-your-key

If the key is invalid, disabled, or the balance is insufficient, the system will return 401 or 403. Please verify your key status and account balance.

4. Quick Start (cURL)

4.1 Non-streaming Chat

curl -X POST https://www.relay-api.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-key" \
  -d '{
    "model": "claude-sonnet-5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Introduce yourself in one sentence"}
    ]
  }'

4.2 Multi-turn conversation with system prompts

curl -X POST https://www.relay-api.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: sk-your-key" \
  -d '{
    "model": "claude-opus-5",
    "max_tokens": 2048,
    "system": "You are a rigorous technical documentation engineer.",
    "messages": [
      {"role": "user", "content": "What are the authentication headers for the Claude Messages API?"},
      {"role": "assistant", "content": "Use x-api-key or Authorization: Bearer to carry your key."},
      {"role": "user", "content": "Give me an example of a streaming request."}
    ],
    "metadata": {"request_id": "demo-001"}
  }'

The metadata.request_id is saved in usage logs, making it easy to reconcile accounts under "User Center → Usage Details".

5. Request Parameters

FieldTypeRequiredDescription
modelstringYesModel slug, e.g., claude-sonnet-5
max_tokensintYesMax output tokens, recommended 1~64000
messagesarrayYesConversation messages, items are {role, content}, role: user / assistant
systemstringNoSystem prompt
temperaturenumberNoSampling temperature, default 1.0, range 0~1
top_pnumberNoNucleus sampling, default 0.999
streamboolNoStreaming output, default false
stop_sequencesarrayNoStop sequences
metadata.request_idstringNoCustom request ID for reconciliation

6. Response Structure

Non-streaming requests return the standard Anthropic Messages structure:

{
  "id": "msg_01ABCDEFG",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5",
  "content": [
    {"type": "text", "text": "Hello! I am Claude."}
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 12,
    "output_tokens": 18,
    "cache_read_input_tokens": 0,
    "cache_creation_input_tokens": 0
  }
}
FieldDescription
idUnique message ID
content[].typeContent block type, text / thinking, etc.
content[].textText content
stop_reasonStop reason: end_turn / max_tokens / stop_sequence
usage.input_tokensInput token count (basis for billing)
usage.output_tokensOutput token count (basis for billing)
usage.cache_read_input_tokensCached input tokens read (billed at cache read rate)
usage.cache_creation_input_tokensTokens written to cache (billed at cache write rate)

7. Streaming Output

When the request body includes "stream": true, the server returns data in chunks via SSE (Server-Sent Events). The event types are identical to Anthropic's:

event: message_start
data: {"type": "message_start", "message": {"id": "msg_...", "model": "claude-sonnet-5"}}

event: content_block_delta
data: {"type": "content_block_delta", "delta": {"type": "text_delta", "text": "Hello"}}

event: message_delta
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn"}, "usage": {"output_tokens": 18}}

event: message_stop
data: {"type": "message_stop"}

Clients should parse the JSON after the data: prefix and ignore event: lines and empty lines. Receiving message_stop indicates the end of the stream. Billing is settled on the server side based on the total usage of the request, independent of the streaming process.

8. Common Error Codes

HTTP StatusMeaningResolution
400Invalid request parameters (missing model/max_tokens, model not enabled, etc.)Correct the request body based on the response message
401Missing or invalid API keyCheck your Authorization / x-api-key headers
403Key disabled, insufficient balance, or model/route not authorizedTop up your account, check key status, or adjust permissions
404Model does not existCheck available models via GET /v1/models
429Too many requests or rate limit triggeredRetry with exponential backoff
500Internal server errorRetry later; contact support if the issue persists

The error response body format is consistent: {"code": status_code, "message": "error description", "data": null}.

9. Usage and Balance

  • Each call is deducted in real-time based on token usage × model unit price × route multiplier. See GET /v1/models for specific pricing and routes.
  • After logging in, view your call history (model, tokens, cost, status) in "User Center → API Usage".
  • If your balance is insufficient, the request will return 403; access is restored immediately upon top-up.