59API

← Back to all guides

First Claude API Call via 59API in Five Minutes

API · EN · 2026-09-03

What You Will Build

In the next five minutes, you will send a real prompt to Claude and print its answer from a terminal. This walkthrough uses the Claude Messages API through 59API, an API relay with the base URL https://api.59api.com. It is a practical option when you want pay-as-you-go Claude access without changing the familiar Anthropic-style request format.

59API supports Claude Opus, Sonnet, Haiku, and Fable models, plus GPT models for projects that need more than one provider. Its native official-quality model access means you are not intentionally trading response quality for a lower-cost route. It is also compatible with Claude Code, Codex, and OpenAI SDK workflows, so this first test can become part of a larger development setup later.

Minute 1: Create a Key and Set a Budget

Create a 59API account, add a small pay-as-you-go balance, and generate an API key in the dashboard. Copy the key once and store it in an environment variable rather than pasting it into source code. On macOS or Linux, run the following command in your terminal:

export FIFTYNINE_API_KEY="your_59api_key_here"

On Windows PowerShell, use:

$env:FIFTYNINE_API_KEY="your_59api_key_here"

Pay-as-you-go pricing is especially useful for prototypes, internal tools, and small agents because you can test a Claude workflow without committing to a large monthly plan.

Minutes 2 and 3: Choose a Claude Model and Prepare the Request

For a first API call, choose a Sonnet model ID listed in your 59API dashboard. Sonnet is usually a sensible starting point for general coding, writing, and reasoning tasks. Haiku is often better when latency and low cost matter most, while Opus is appropriate for demanding reasoning tasks. Model availability and exact IDs can change, so use the current identifier shown by 59API rather than guessing.

The Claude Messages API needs four main pieces: the endpoint, your API key, an Anthropic version header, and a JSON body containing a model, token limit, and user message. The relay endpoint is:

https://api.59api.com/v1/messages

Create your first request with cURL. Replace the example model ID with the Sonnet model ID from your dashboard if needed:

curl https://api.59api.com/v1/messages \ --header "x-api-key: $FIFTYNINE_API_KEY" \ --header "anthropic-version: 2023-06-01" \ --header "content-type: application/json" \ --data '{"model":"claude-sonnet-4-20250514","max_tokens":300,"messages":[{"role":"user","content":"Explain the difference between a list and a tuple in Python in three bullet points."}]}'

Minute 4: Run It and Read the Response

Paste the command into your terminal and press Enter. A successful response is JSON. Look for the content array and then the text value inside its first item. That is Claude's answer. You will also usually receive usage information, including input and output token counts, which helps you understand how prompt length and response length affect spend.

Your application should not assume every request succeeds. A 401-style authentication error usually means the API key is missing, invalid, or not being passed by your shell. A 400-style error commonly points to an unsupported model ID or malformed JSON. If you receive a rate-limit or balance-related response, check your 59API dashboard before automatically retrying.

Minute 5: Make the Same Call from Python

If you already use the Anthropic Python SDK, point its base URL at 59API instead of rewriting your application logic. Install the package with pip install anthropic, then use this minimal pattern:

from anthropic import Anthropic client = Anthropic( api_key=os.environ["FIFTYNINE_API_KEY"], base_url="https://api.59api.com" ) message = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=300, messages=[{"role": "user", "content": "Write one friendly welcome sentence."}] ) print(message.content[0].text)

Add import os at the top, then run the script. Once this works, move your prompt into a function, log token usage, and add timeouts and retry handling before deploying. If you are looking for a low-cost way to start building with Claude, you can sign up for 59API and use its referral rebate when sharing it with other developers.

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