Claude API Getting Started: Hello World Guide
Getting started with the Claude API
If you're searching for "claude api getting started hello world," you want the fastest path from zero to a working request: get credentials, install whatever you need, send one message, and see Claude respond. This guide walks through that exact path using plain HTTP calls, so it works regardless of which language or framework you end up using.
By the end, you'll have a working script that sends a prompt to Claude and prints the response — the minimum viable "hello world" for any LLM integration.
What you actually need
Before writing any code, you need three things:
- An API key — a credential that authenticates your requests.
- An HTTP client —
curl,fetch,axios, or whatever your language ships with. No SDK is strictly required. - A model name — the identifier for the Claude model you want to call.
You do not need a framework, an SDK, or a backend server to send your first request. A single terminal command is enough to prove the connection works.
Step 1: Get an API key
Anthropic issues keys through its own console if you want direct access. If you'd rather skip infrastructure setup — rate limit handling, billing dashboards, team key management — you can also get an HTTPS API key through SubToAPI, which turns your existing Claude access into a sub_live_... key with streaming, usage metadata, and team seats built in. Either way, the request shape below is the same: a bearer token in the Authorization header.
Sign up at /signup if you want a key in under a minute, or check /pricing for plan details (Solo, Team, Scale, all with a free trial).
Step 2: Send your first request with curl
This is the actual "hello world." Open a terminal and run:
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4",
"max_tokens": 100,
"messages": [
{ "role": "user", "content": "Say hello world and explain what you are in one sentence." }
]
}'
If everything's wired correctly, you'll get back a JSON object with a content array containing Claude's reply, plus usage metadata (input/output token counts). That response is your proof the pipeline works end to end: auth, request, model, response.
Full parameter details live at /docs/messages, and a broader walkthrough covering setup and first calls is at /docs/quickstart.
Step 3: Do the same thing in JavaScript
Most real projects won't use raw curl, so here's the equivalent in Node.js using fetch:
const response = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "claude-sonnet-4",
max_tokens: 100,
messages: [
{ role: "user", content: "Say hello world and explain what you are in one sentence." }
]
})
});
const data = await response.json();
console.log(data.content[0].text);
Run this with node hello.js after setting SUBTOAPI_KEY in your environment. That's the entire "hello world" — no SDK installation, no boilerplate client classes, just a POST request and a JSON response.
Understanding the response shape
A typical response looks roughly like this:
{
"id": "msg_01...",
"model": "claude-sonnet-4",
"role": "assistant",
"content": [
{ "type": "text", "text": "Hello world! I'm Claude, an AI assistant made by Anthropic." }
],
"usage": {
"input_tokens": 18,
"output_tokens": 22
}
}
Three things worth noting as a beginner:
contentis an array, not a plain string. A response can include multiple blocks (text, tool calls, etc.), so you access the text viacontent[0].text.usagegives you token counts for both sides of the conversation — useful once you start caring about cost.roleon the response is always"assistant". Your input messages use"role": "user".
Common mistakes when starting out
A few things trip up almost everyone on their first Claude API call:
- Forgetting
max_tokens. It's required on every request — there's no default, so omitting it returns an error immediately. - Sending the API key in the wrong header. It goes in
Authorization: Bearer <key>, not a custom header, when using an OpenAI-style gateway like SubToAPI. If you're calling Anthropic's API directly, their header format differs slightly, so check whichever docs match your provider. - Treating the response as plain text. Beginners often try
data.contentdirectly and get an array instead of a string, leading to confusing[object Object]output. - Not handling rate limits or retries. Your hello-world script doesn't need this, but any production code should expect occasional 429s and back off accordingly.
Where to go after hello world
Once a single request works, the natural next steps are:
- Streaming — getting tokens back as they're generated instead of waiting for the full response. See /docs/streaming.
- Tool use — letting Claude call functions you define, useful for anything beyond plain text generation. See /docs/tools.
- Multi-turn conversations — passing prior messages back in the
messagesarray so Claude has context.
None of these require throwing away your hello-world script — they're additions to the same request/response pattern you just built.
questions
Do I need Anthropic's SDK to get started? No. Any HTTP client works — curl, fetch, axios, requests in Python. SDKs are convenience wrappers around the same JSON API calls shown above.
Why does my request fail with a 401 error? Almost always an invalid or missing API key, or the key placed in the wrong header. Double-check you're sending Authorization: Bearer <your-key> exactly, with no extra whitespace or quotes.
What's the cheapest way to test the Claude API without committing to infrastructure? Start with a free trial — both Anthropic directly and gateways like SubToAPI offer one at /signup — and run a handful of curl requests before writing any application code. That's enough to validate the integration before you invest in SDKs, retries, or streaming logic.