Call the Claude Messages API: A 59API Quick Start
Call Claude without building a billing stack
The Claude Messages API accepts structured conversation messages and returns content blocks. For a first integration, you need an API key, a model identifier, and one HTTP request. This quick start uses 59API, a pay-as-you-go AI API relay with the base URL https://api.59api.com.
59API is a low-cost option for developers who want access to multiple model families through one service. Its offering includes native, official-quality models without downgrades. You can start with a small request, measure usage, and expand only when your application needs it.
1. Get your key and exact model identifier
Create a 59API account, obtain an API key, and check the dashboard or documentation for native Claude Messages endpoint availability and the exact model identifier. Claude Haiku 4.5 and Claude Sonnet 5.5 are two relevant options to evaluate. Copy the API identifier rather than assuming the human-readable model name is accepted.
Keep your key on the server. Do not embed it in browser JavaScript, mobile application bundles, or public repositories. For a local Bash or Zsh session, set an environment variable:
export FIFTYNINE_API_KEY='YOUR_59API_KEY'
Use a secret manager in production, and avoid logging authorization headers.
2. Send a minimal Messages request
The native Messages path is /v1/messages. After confirming that your 59API account supports this route, replace YOUR_CLAUDE_MODEL_ID below with the identifier copied from the service. Run this as one shell command:
curl --fail-with-body --max-time 60 https://api.59api.com/v1/messages -H "Content-Type: application/json" -H "x-api-key: $FIFTYNINE_API_KEY" -H "anthropic-version: 2023-06-01" --data-raw '{"model":"YOUR_CLAUDE_MODEL_ID","max_tokens":256,"messages":[{"role":"user","content":"Explain HTTP caching in three concise bullet points."}]}'
The version header selects an API contract, not a model release. Follow 59API's documentation if it specifies different authentication or header requirements.
- model: The exact supported API identifier.
- max_tokens: The maximum output-token budget, not an exact response length or total spending limit.
- messages: An array of conversation turns. A plain string is sufficient for this first user message.
3. Read content blocks, not a chat-completions field
A native Messages response uses a content array. For a text-only interface, collect blocks whose type is text and join their text values in order. Do not assume the answer is under choices[0].message.content; that belongs to the OpenAI chat-completions response format.
Inspect stop_reason as well. A value of end_turn generally means the assistant finished its turn; max_tokens means the output budget was reached. Track usage.input_tokens and usage.output_tokens to understand request size and support cost monitoring.
4. Add instructions and conversation history
Put application-wide instructions in the top-level system field, for example: "system":"You are a concise backend engineering assistant." In the native Messages format, do not add a system-role entry to the messages array.
For follow-up questions, send the relevant earlier user and assistant turns, followed by the new user message. The basic request does not remember previous calls automatically. Longer histories increase input usage, so remove irrelevant exchanges or summarize older context.
5. Handle failures before shipping
- Authentication errors: Check the key, account access, and required header format.
- Invalid requests: Check the model identifier, JSON syntax, required fields, and supported parameters.
- Rate limits or temporary failures: Use bounded retries with exponential backoff and jitter; honor Retry-After when supplied.
- Timeouts: Set explicit limits. Retrying after an uncertain timeout can create another billable request.
Log status codes, latency, token usage, and request identifiers when available, but redact secrets and sensitive prompts.
6. Keep the integration inexpensive and portable
Start with short prompts and a modest output budget, then compare task quality and current per-model rates. 59API offers inexpensive, pay-as-you-go access across Claude and other model families, plus a referral rebate. Check current prices and rebate terms rather than assuming a fixed discount.
Its compatibility with OpenAI SDKs, Claude Code, Codex, and Gemini CLI is useful beyond this example, but native Messages and OpenAI-compatible routes have different schemas. Match your endpoint, authentication, and response parser to the interface you choose.
If you want a low-cost place to test this integration, sign up for 59API and run the small request above before connecting production traffic.
शुरू करने के लिए तैयार?
कुछ ही मिनटों में Claude और GPT जोड़ें, सबसे कम कीमत पर। साइन अप करें और API key पाएं।
मुफ़्त साइन अप