Authentication
How to use Bearer token authentication with cURL
Bearer token authentication in curl uses an Authorization header with the format Authorization: Bearer YOUR_TOKEN.
Bearer token example
Many APIs use bearer tokens for OAuth access tokens, personal access tokens, or temporary API credentials. The token proves that the caller is allowed to access the resource.
curl https://api.example.com/me \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"Do not expose real tokens
Bearer tokens are secrets. Anyone with the token may be able to access your account or API. Do not paste real tokens into public logs, GitHub issues, blog comments, or support tickets.
When writing examples, replace the token with YOUR_ACCESS_TOKEN or another obvious placeholder.
Bearer tokens in code
When converted to code, the bearer token remains an Authorization header. In production code, store it in an environment variable or secret manager instead of hard-coding it.
Common auth errors
A 401 response usually means the token is missing, expired, malformed, or not accepted by the API. A 403 response usually means the token is valid but lacks permission.
Try it with curlcode
Have a curl command already? Paste it into one of the converters below to generate language-specific HTTP request code.
Frequently asked questions
What does Bearer mean?
It means whoever bears or presents the token is treated as authenticated for the request.
Is Bearer token the same as API key?
Not always. Some APIs use API keys in custom headers, while OAuth-style APIs often use bearer tokens.
Should I hard-code bearer tokens?
No. Use environment variables or a secure secret store in real projects.
Can I convert bearer-auth curl to code?
Yes. The Authorization header maps directly into most HTTP clients.
Related guides
What does cURL mean?
Learn what cURL means, why developers use it, and how a simple curl command turns a URL into a repeatable API request.
What is a cURL command?
A practical explanation of curl commands, their structure, common flags, and how developers use them to test APIs.
How to copy as cURL from Chrome DevTools
Use Chrome DevTools to copy a real browser request as cURL, inspect headers and cookies, and convert it into reusable code.