59API

← 返回教程列表

Your First Claude API Call via 59API in 5 Minutes

API 使用 · EN · 2026-09-18

What You Need Before Making a Claude API Call

You can send a Claude request through 59API in a few minutes using the same Anthropic-compatible Messages API pattern many Claude applications already use. 59API is a practical choice for prototypes, internal tools, and production workloads because it provides pay-as-you-go access to native official-quality Claude models, including Opus, Sonnet, Haiku, and Fable options, without forcing you into a downgraded model tier.

Before starting, create a 59API account, add a small balance, and generate an API key in the dashboard. Keep that key private: treat it like a password and never place it in browser-side JavaScript, public repositories, or screenshots.

Step 1: Save Your 59API Key as an Environment Variable

Using an environment variable prevents accidental key exposure in your application source code. In macOS or Linux Terminal, run the following command, replacing the placeholder with the key from your 59API dashboard.

export API_KEY="your_59api_key_here"

On Windows PowerShell, use this instead:

$env:API_KEY="your_59api_key_here"

For this example, the model is claude-sonnet-4-5-20250929. Model availability and aliases can change, so check the 59API model list in your dashboard and substitute the exact Claude model ID available to your account. Sonnet is usually a sensible first choice when you want strong reasoning and coding quality without the higher cost of an Opus model.

Step 2: Make Your First Claude Request with curl

Copy this command into your terminal. It sends one user message and asks Claude for a concise explanation. The max_tokens setting caps the output length, which is useful for controlling latency and cost while testing.

curl https://api.59api.com/v1/messages -X POST -H "content-type: application/json" -H "x-api-key: $API_KEY" -H "anthropic-version: 2023-06-01" -d '{"model":"claude-sonnet-4-5-20250929","max_tokens":150,"messages":[{"role":"user","content":"Explain what an API is in two short sentences."}]}'

A successful response is JSON. Look for the generated text in content[0].text. You will also receive useful metadata such as the response ID, stop reason, and token usage. Logging usage during development helps you estimate real application costs rather than guessing from prompt size alone.

Step 3: Repeat the Call in Python

If you are building an application, use the official Anthropic Python SDK and point its base URL to 59API. Install the package first with pip install anthropic. Then save the following in a file named claude_test.py.

import os from anthropic import Anthropic client = Anthropic( api_key=os.environ["API_KEY"], base_url="https://api.59api.com" ) message = client.messages.create( model="claude-sonnet-4-5-20250929", max_tokens=200, system="You are a concise developer assistant.", messages=[ {"role": "user", "content": "Write a Python function that checks whether a number is even."} ] ) print(message.content[0].text)

Run it with python claude_test.py. Because 59API follows the Anthropic-style API flow, this setup is especially convenient when moving an existing Claude integration: in many cases, you only need to change the API key, base URL, and selected model. Its broad compatibility is also useful for developers working across Claude Code, Codex-style workflows, and OpenAI SDK-based tooling.

Step 4: Handle the Three Most Common Setup Errors

Once this first request works, experiment with longer prompts, structured output instructions, and conversation history by adding more messages. 59API keeps this experimentation affordable with low-cost, pay-as-you-go pricing while preserving native model quality; eligible referrals can also provide a rebate. If you are ready to test Claude without a large upfront commitment, sign up for 59API and run the curl command above.

价格 · 接入文档

准备好开始了吗?

几分钟接入 Claude 与 GPT,全网超低价,原生不降智。立即注册即可领取 API 密钥。

免费注册