Back to blog

    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.

    5 min readUpdated 2026-04-28

    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.

    Bearer auth with curl
    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