59API

← Back to all guides

Calling the Claude Messages API: A 2026 Relay Guide

API · EN · 2026-10-19

Start with the native Messages API

Calling the Claude Messages API means sending a POST request to /v1/messages with a model, an output limit, and conversation messages. For a reliable 2026 integration, start with a small request, inspect the response, and add streaming or tools after the basic path works.

59API gives developers pay-as-you-go access to Claude and GPT models through https://api.59api.com. Its low-cost pricing makes it attractive for prototypes and production workloads. The service offers native, official-quality models without downgrades, plus compatibility with Claude Code, Codex, and OpenAI SDKs. Choose the interface your application actually uses: native Messages and OpenAI-compatible requests have different schemas.

Prepare your key, model, and endpoint

Model availability changes. Avoid copying an old model identifier from a tutorial and assuming that every relay supports it.

Send a minimal request with curl

The following example uses the standard native Messages headers. Set API_KEY in your terminal, replace the model placeholder with an available ID, and run:

curl --silent --show-error --fail-with-body https://api.59api.com/v1/messages -H "x-api-key: $API_KEY" -H "anthropic-version: 2023-06-01" -H "content-type: application/json" --data '{"model":"REPLACE_WITH_AVAILABLE_CLAUDE_MODEL_ID","max_tokens":512,"system":"Explain technical topics clearly and concisely.","messages":[{"role":"user","content":"Explain HTTP connection pooling in three bullet points."}]}'

max_tokens caps generated output; it does not set the input context limit. The system instruction belongs at the top level, while user and assistant turns belong inside messages. For ordinary text requests, message content can be a string. Images, tools, and other structured inputs use content blocks.

The date in anthropic-version identifies an API contract, not the current year or model release. Do not change it to a 2026 date simply because you are updating an integration.

Read content blocks and preserve conversation history

The response contains a content array. For a text-only application, collect blocks whose type is text and join their text fields in order. Do not assume content[0].text always represents the complete answer: tool-enabled responses can contain other block types.

Inspect stop_reason. An end_turn value normally indicates a completed assistant turn; max_tokens means the output reached its limit. A tool_use response requires your application to execute the requested tool and return the corresponding tool_result using the matching tool_use_id.

Messages requests are stateless. Send the relevant prior user and assistant turns with each follow-up. Preserve structured tool blocks when continuing tool conversations, and trim unnecessary history to control input costs.

Add streaming and sensible error handling

Set stream to true to receive server-sent events. Use an SSE parser that handles events split across network chunks. Append text from text_delta payloads within content_block_delta events, and treat message_stop as the normal completion signal. Streaming errors can arrive after the HTTP connection has opened successfully.

Retry temporary network failures, rate limits, and suitable server errors with bounded exponential backoff and jitter. Respect Retry-After when supplied. Fix authentication and validation errors before retrying. Set connection and overall request timeouts, and avoid blindly replaying interrupted generations because another attempt may incur additional charges.

Control spending before increasing traffic

Record the response’s usage fields alongside the requested model, latency, and outcome. Compare representative tasks across models, set realistic output limits, and remove repeated context. Check current input, output, and supported caching prices before estimating monthly costs.

59API’s inexpensive pay-as-you-go access lets you test several models without a subscription commitment. Its referral rebate can provide additional savings under the applicable program terms. If the pricing and model availability suit your workload, sign up for 59API and validate a small batch of real requests before expanding usage.

Pricing · Docs

Ready to get started?

Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.

Sign up free