← Blog

LLM API Key: What It Is and How to Get One

2026-09-04 · 5 min read · SubToAPI Team

An LLM API key is a secret credential that authenticates your application when it makes requests to a large language model provider's API. Instead of logging in through a browser, your code sends this key with every HTTP request, and the provider uses it to identify your account, apply rate limits, meter usage for billing, and authorize which models and features you can access.

If you're trying to figure out how to get one, the short answer is: sign up for a developer account with an LLM provider (or a service that sits on top of one), generate a key from a dashboard, and store it as an environment variable in your app. The rest of this guide covers the details — how the authentication actually works, where to get a key, and how to avoid the mistakes that get keys leaked or accounts suspended.

How LLM API key authentication works

Almost every LLM API uses the same basic pattern: a bearer token sent in the Authorization header of an HTTPS request.

curl https://api.example.com/v1/chat \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"model": "some-model", "messages": [{"role": "user", "content": "Hello"}]}'

The server validates the key, checks your account's permissions and remaining quota, processes the request, and returns a response — usually JSON, or a stream of server-sent events if you've requested streaming output. There's no session, no cookie, no login flow: the key itself is the entire authentication mechanism, which is why keeping it secret matters so much.

Most providers prefix keys so you can identify them at a glance (sk-, sk-ant-, and similar patterns), and most let you generate multiple keys per account so you can scope access by project, environment, or team member.

Where to get an LLM API key

You generally have two paths:

1. Go direct to a model provider. Anthropic, OpenAI, Google, and others each have their own developer console where you create an account, add a payment method, and generate keys. This gives you the most direct access to the provider's full feature set and latest models, but it also means separate billing, separate dashboards, and separate rate-limit pools if you use more than one provider.

2. Use a platform built on top of a provider. These services issue their own API keys but route requests to an underlying model, often adding features like unified billing, team management, or usage dashboards that the raw provider API doesn't include.

SubToAPI is an example of the second path for Claude specifically: it turns an existing Claude subscription into an HTTPS API with its own sub_live_... application keys, so you get streaming, tool use, and usage metadata without setting up separate provider billing. You generate a key from the dashboard after signup and use it exactly like any other LLM API key:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Summarize this in one sentence: ..."}]
  }'

Whichever route you choose, the mechanics on your side are identical: get a key, keep it in an environment variable, send it as a bearer token.

Setting up a key correctly

Once you have a key, the setup pattern is the same regardless of provider:

# .env (never commit this file)
LLM_API_KEY=sk-your-key-here
const apiKey = process.env.LLM_API_KEY;

const response = await fetch("https://api.example.com/v1/chat", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${apiKey}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "some-model",
    messages: [{ role: "user", content: "Hello" }]
  })
});

Add .env to .gitignore before you write a single line of code that uses the key. This sounds obvious, but committed API keys are one of the most common causes of surprise bills — scanners crawl public GitHub repos specifically looking for leaked credentials, and a leaked key can be used within minutes.

For a SubToAPI-specific walkthrough with request and response examples, see the quickstart guide and the messages API reference.

Managing keys safely

A few practices matter regardless of which provider you use:

If you're managing keys across a team, look for a provider with role-based access and per-member key issuance rather than sharing a single key across every developer — it makes revocation and auditing far simpler when someone leaves the project.

Streaming and tool use

Most modern LLM APIs support two features beyond a plain request/response call: streaming, where tokens arrive incrementally over a persistent connection instead of all at once, and tool use (also called function calling), where the model can request that your application run a function and return the result before continuing. Both use the same API key and authentication pattern described above — they just change the shape of the request and response. If you're building anything interactive, check your provider's docs for streaming and tool use support before you architect around a single blocking call.

Questions

Is an LLM API key the same as a password? Functionally, yes — anyone with the key can act as your account within its permissions and rate limits. Treat it with the same care as a password or private key, and never expose it in client-side code, logs, or public repos.

Can I use one LLM API key across multiple apps? You can, but it's not recommended. Separate keys per app or environment make it easier to track usage, set limits, and revoke access without affecting unrelated projects.

What happens if my LLM API key is leaked? Revoke it immediately from your provider's dashboard and generate a new one. Update every service using the old key, and check your usage logs for unexpected activity during the exposure window.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →