How to Get an Access Token for the Apache Airflow® REST API
Apache Airflow® 3 has a REST API for everything the UI does: list Dags, trigger runs, read logs. Most of its endpoints refuse a request that doesn't prove who's asking. With the simple auth manager that airflow standalone uses, the proof is a JWT access token, which you get by posting a username and password to /auth/token. This guide gets one and uses it, on Airflow 3.4.0.
Syntax
Get a token:
curl -X POST <airflow URL>/auth/token \
-H 'Content-Type: application/json' \
-d '{"username": "<username>", "password": "<password>"}'
Use it:
curl <airflow URL>/api/v2/<endpoint> -H "Authorization: Bearer <token>"
| Part | What it means |
|---|---|
<airflow URL> | Where the API server runs, such as http://localhost:8080 |
/auth/token | The simple auth manager's endpoint that creates tokens |
-d '{…}' | The username and password, as JSON |
/api/v2/<endpoint> | Any REST API endpoint, such as /api/v2/pools |
Authorization: Bearer <token> | The header that carries the token |
Airflow's guide to generating a token with the simple auth manager uses exactly this curl -X 'POST' request, and says it returns a token "that you can use in the Airflow public API requests".
Prerequisites
- Apache Airflow® running with the simple auth manager, which
airflow standaloneuses. - The admin password, from
simple_auth_manager_passwords.json.generatedin yourAIRFLOW_HOME.
Step 1: Request a Token
My API server is on http://127.0.0.1:8085. Put your own password in place of <password>:
curl -s -X POST http://127.0.0.1:8085/auth/token \
-H 'Content-Type: application/json' \
-d '{"username": "admin", "password": "<password>"}'
{"access_token":"eyJ...(masked)"}

The answer is one JSON field, access_token. Its value is a JWT, a long string that starts with eyJ; I masked mine, because anyone holding it can use the API as admin until it expires. -s hides curl's progress meter.
Step 2: Call the API Without It
curl -s http://127.0.0.1:8085/api/v2/pools
{"detail":"Not authenticated"}
The API refuses: no token, no data.
Step 3: Call It With the Token
The quickest way is to keep the token in a variable. This line asks for a token and keeps only its value:
TOKEN=$(curl -s -X POST http://127.0.0.1:8085/auth/token \
-H 'Content-Type: application/json' \
-d '{"username": "admin", "password": "<password>"}' \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["access_token"])')
curl -s http://127.0.0.1:8085/api/v2/pools -H "Authorization: Bearer $TOKEN"
{"pools":[{"name":"default_pool","slots":128,"description":"Default pool","include_deferred":false,"occupied_slots":0,"running_slots":0,"queued_slots":0,"scheduled_slots":0,"open_slots":128,"deferred_slots":0,"team_name"...

With the token, the same request returns Airflow's pools: default_pool, with 128 slots. The small Python program in the first command reads the JSON answer and prints only access_token.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Testing with /api/v2/version | It answers without a token, so it proves nothing | Use an endpoint such as /api/v2/pools |
| Pasting a token into a post, chat or ticket | Anyone can use the API as you until it expires | Treat it like a password |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
{"detail":"Not authenticated"} | No Authorization header, or no token in it | Add -H "Authorization: Bearer $TOKEN" |
An empty TOKEN variable | The token request's answer had no access_token | Run the first curl alone and read its answer |
FAQ
How long is a token valid?
24 hours by default: [api_auth] jwt_expiration_time is 86400 seconds.
Does this work with other auth managers?
This endpoint is the simple auth manager's. Other auth managers have their own way of issuing tokens.
Why do I see a warning about the HMAC key in Airflow's output?
Airflow signs tokens with a generated key that's shorter than recommended; Fixed: The HMAC key is 24 bytes long shows the fix.
Conclusion
A POST to /auth/token with the admin's username and password returned an access_token. Without it, /api/v2/pools answered Not authenticated; with Authorization: Bearer and the token, it returned the default_pool.
Additional Resources
- Generate JWT token with simple auth manager — the official example.
- REST API reference — every endpoint.
Apache®, Apache Airflow and Airflow® are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.
