Course contentsShow
← AI Engineering
Lesson 99 of 1,8863. API-First AI EngineeringFree lesson

Bearer Token Authentication

Understanding bearer token authentication patterns used by OpenAI, Anthropic, and other LLM providers.

Bearer Token Authentication

What you'll learn: How LLM providers like OpenAI and Anthropic authenticate your API requests using bearer tokens.

What is Bearer Token Authentication?

Bearer token authentication is like showing a special pass to enter a restricted area. When you call an API like OpenAI's, you include your API key in the request header, and the server checks that "pass" to verify you're authorized.

The word "bearer" means "whoever holds this token." If you have the token, you can use the API—no password or username needed beyond the token itself.

How It Works

When you make an API request, you send your API key in an HTTP header called Authorization, formatted like this:

Authorization: Bearer YOUR_API_KEY_HERE

The pattern is always: the word "Bearer", then a space, then your actual API key (which you've already stored as an environment variable).

This happens automatically when you use SDK clients like the OpenAI Python library—you provide the key once during setup, and the library adds the correct header to every request behind the scenes.

Why "Bearer" Matters

Different APIs use different authentication methods (OAuth, API signatures, etc.), but most modern LLM providers standardized on bearer tokens because they're simple and stateless. The server doesn't need to remember you between requests—each request carries its own proof of authorization.

This is why protecting your API keys is critical: anyone with your bearer token can make requests as you, spending your budget and accessing your resources.

Key Takeaway: Bearer token authentication requires you to include your API key in an Authorization: Bearer <token> header with each request, allowing stateless verification of your identity and permissions.