How to Access LLM API: A Practical Setup Guide
"Accessing an LLM API" means getting past the authentication layer and successfully sending an HTTP request to a model provider's endpoint, and getting a valid response back. That's the whole mechanical problem: you need a valid credential, the right endpoint URL, correctly formatted headers, and a request body the API understands. Everything else — SDKs, frameworks, wrappers — is convenience on top of that.
There are two broad paths to get there. The first is going directly to a model vendor (Anthropic, OpenAI, Google, etc.), creating a developer account, and generating a key tied to a billing plan. The second is going through a service that already has access and exposes it to you under a simpler contract — for example, turning an existing Claude subscription into an HTTPS API through a proxy like SubToAPI. Which path fits depends on whether you already have model access through a consumer plan, or you're starting from zero.
Step 1: Decide which access method fits your situation
Before touching code, figure out which of these describes you:
- You have no existing LLM subscription. Go directly to a provider, create a developer/console account, add a payment method, and generate an API key.
- You already pay for a consumer plan (like Claude Pro/Max) but want programmatic access without opening a separate developer billing account. A service like SubToAPI sits on top of your existing access and exposes it as a standard API key (
sub_live_...), so you skip the separate provider billing setup entirely. - You're building a product for other people and need per-user or per-team keys, usage tracking, and seat management rather than one shared credential.
Each of these leads to a different account creation flow, but the resulting mechanics — key, endpoint, headers, JSON body — are the same.
Step 2: Create the account and generate a key
For a direct provider account, this usually means:
- Sign up at the provider's console.
- Verify email and add a payment method (most LLM APIs are prepaid or postpaid, rarely free-forever for production volume).
- Navigate to the API keys section and generate a key.
- Store it as an environment variable — never hardcode it, never commit it.
For SubToAPI, the flow is shorter because there's no separate provider billing step:
- Create an account at /signup.
- Generate an application key from the dashboard (format
sub_live_...). - Use it directly against
https://api.subtoapi.app/v1/....
Either way, treat the key as a secret. Rotate it if it leaks, scope it per environment (dev/staging/prod), and never expose it in frontend JavaScript.
Step 3: Make your first authenticated request
Once you have a key, access comes down to sending an HTTP POST with an Authorization header. Here's the shape using curl against SubToAPI:
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4",
"max_tokens": 512,
"messages": [
{"role": "user", "content": "Summarize this API access flow in two sentences."}
]
}'
And the same in JavaScript with 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: 512,
messages: [{ role: "user", content: "Summarize this API access flow in two sentences." }],
}),
});
const data = await response.json();
console.log(data);
If this returns a 200 with a content array, you have working access. If it doesn't, the failure almost always falls into one of the categories below.
Step 4: Understand the parts you're actually accessing
A full request/response cycle touches four things worth knowing explicitly:
- Endpoint — the URL path (
/v1/messagesfor chat-style completions, sometimes a separate path for embeddings or completions-only models). - Auth header — nearly universally
Authorization: Bearer <key>, though some providers use a custom header name. - Request body — model name, message array,
max_tokens, and optional parameters liketemperatureorstream. - Response format — JSON for standard calls, server-sent events for streaming. See /docs/messages and /docs/streaming for the exact shapes if you're using SubToAPI.
If your use case involves letting the model call functions in your codebase (database lookups, calculators, search), that's tool use — covered in /docs/tools — and it changes the request body shape but not the authentication mechanics.
Common access errors and what they mean
- 401 Unauthorized — key missing, malformed, or revoked. Check the header name and that you're not sending an expired key.
- 403 Forbidden — key is valid but lacks permission for that model or endpoint, often a plan/tier restriction.
- 429 Too Many Requests — you've hit a rate limit. Back off and retry with exponential delay; don't hammer the endpoint.
- CORS errors in the browser — LLM APIs are not meant to be called directly from client-side JavaScript with a secret key exposed. Route calls through your own backend.
- Timeout on long responses — use streaming instead of waiting for the full completion in one shot.
For anyone getting started, /docs/quickstart walks through the first request end to end, including key generation and a working code sample, which is the fastest way to confirm your access is set up correctly before building anything on top of it.
Choosing based on how much setup you want
If you're comfortable managing separate developer billing, rate limits, and key rotation per provider, going direct works fine and gives you the most control over model choice. If you already have a Claude subscription and want API-level access — streaming, tool use, usage metadata, multiple team keys — without duplicating billing, a layer like SubToAPI gets you from signup to a working sub_live_... key in minutes, with plans starting at €9/month for solo use and per-seat pricing for teams (see /pricing).
questions
Do I need a credit card to access an LLM API? Most providers require a payment method before issuing a production-ready key, even if there's a free trial or credit period. Some offer limited free tiers, but sustained access almost always requires billing setup.
Can I access an LLM API without writing backend code? No — API keys must never be exposed in browser JavaScript, so you need at least a minimal server or serverless function to hold the key and forward requests.
What's the difference between accessing a model API and using a chat app subscription? A chat subscription gives you a UI for one conversation at a time. API access gives you programmatic HTTPS calls you can integrate into your own product, with structured JSON in and out, streaming, and usage data per call.