Your First Claude API Call in 5 Minutes with 59API
One SDK, one request, one working response
You do not need a full application to start using Claude. This quick-start guide takes you from an API key to a short Claude response using Python and the OpenAI SDK.
We will use 59API, an AI API relay with pay-as-you-go access to Claude and GPT models. Its API origin is https://api.59api.com. The OpenAI-compatible interface lets you keep familiar SDK code while changing the endpoint, credentials, and model.
Before starting: have Python 3.9 or newer, a terminal, and a funded 59API account ready. Account setup or payment processing may take longer than the five-minute coding portion.
Minute 1: Get your key and exact model ID
Open your 59API dashboard, create an API key, and check that your account has available credit. Copy the key somewhere temporary and private; never put it in a public repository, browser JavaScript, or a screenshot.
Next, copy an available Claude model identifier exactly as shown in the dashboard or model documentation. A display label such as “Sonnet” is not necessarily a valid API model ID. Availability, identifiers, and prices can change, so avoid guessing a model name from an older tutorial.
For a simple connectivity test, choose a lower-cost Haiku option if available. You can switch to Sonnet or Opus after the request works.
Minute 2: Install the SDK
These commands use a macOS or Linux shell. Create an isolated environment and install the OpenAI Python package:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade openai
On Windows PowerShell, activate the environment with .venv\Scripts\Activate.ps1 instead. The Python request below stays the same, but environment-variable assignment uses PowerShell syntax.
Minute 3: Configure the connection
In your activated macOS or Linux terminal, set these environment variables, replacing both placeholders:
export OPENAI_API_KEY='PASTE_YOUR_59API_KEY'
export OPENAI_BASE_URL='https://api.59api.com/v1'
export CLAUDE_MODEL='PASTE_EXACT_CLAUDE_MODEL_ID'
Check the endpoint: /v1 is the conventional OpenAI-compatible API prefix used in this example. Confirm the full base URL against your 59API dashboard or current documentation. If it provides a different path, use that value. Do not append /chat/completions to the SDK base URL; the SDK adds the resource path.
The variable name OPENAI_API_KEY is an SDK convention. Its value here must be your 59API key, not an OpenAI or Anthropic key.
Minute 4: Send your first Claude request
Run this single-line Python command in the same terminal:
python -c 'import os; from openai import OpenAI; client = OpenAI(timeout=30.0, max_retries=0); response = client.chat.completions.create(model=os.environ["CLAUDE_MODEL"], messages=[{"role":"user","content":"Explain an HTTP 429 error in two sentences for a junior developer."}], max_tokens=150); print(response.choices[0].message.content); print("Usage:", response.usage)'
You should receive a short explanation followed by usage information, when returned by the relay. The request uses Chat Completions, one user message, and a small output limit. There is no streaming, tool execution, or conversation history to complicate your first test.
Why disable retries? During setup, one attempt makes errors easier to diagnose. In production, add bounded retries with backoff for temporary failures rather than retrying every error indiscriminately.
Minute 5: Check errors and spending
- 401 or authentication error: verify the key, remove accidental spaces, and confirm the variables were set in this terminal.
- 404 or model-not-found error: check both the base URL path and the exact model ID.
- 429 or quota error: inspect the error body for rate limits, account balance, or model-specific restrictions before retrying.
- Timeout: check connectivity and service status; increase the timeout only after ruling out configuration problems.
Review the request in your dashboard. Input and output tokens may have different prices, and a short prompt can still produce expensive output without a cap.
Keep the next request inexpensive
59API positions itself among the cheapest relays and states that it supplies native, official-quality models without downgrading. Compare current per-model rates rather than assuming every model is equally cheap. Pay-as-you-go billing suits experiments, while its referral rebate may offer additional savings under the current program terms.
Ready to try it? Sign up for 59API, choose a low-cost Claude model, and start with the small request above before adding longer prompts or production traffic.