# Poll every 5 seconds
curl -X POST "https://api.danubeai.com/v1/auth/device/token" \
-H "Content-Type: application/json" \
-d '{"device_code": "dc_a1b2c3d4e5f6..."}'
{
"api_key": "3q2xJd0eK9mPzV5tR8wYs1uB4nC7fH6gLsA2iDoXk5U",
"key_prefix": "3q2xJd0e"
}
Device Auth
Poll Device Token
Poll for an API key after device code authorization
POST
/
v1
/
auth
/
device
/
token
# Poll every 5 seconds
curl -X POST "https://api.danubeai.com/v1/auth/device/token" \
-H "Content-Type: application/json" \
-d '{"device_code": "dc_a1b2c3d4e5f6..."}'
{
"api_key": "3q2xJd0eK9mPzV5tR8wYs1uB4nC7fH6gLsA2iDoXk5U",
"key_prefix": "3q2xJd0e"
}
Overview
Polls for the result of a device authorization flow. The agent should call this endpoint every 5 seconds (theinterval from the device code response) until it receives an API key or the code expires.
No authentication required.
Body Parameters
string
required
The
device_code returned by Create Device CodeResponse
Success (200) — User has authorized
string
The API key to use for future requests — an opaque ~43-character token with no fixed prefix
string
First 8 characters of the key
Pending (428) — User hasn’t authorized yet
{
"error": {
"code": "precondition_required",
"message": "authorization_pending"
}
}
interval seconds.
Expired (410) — Code has expired or been used
{
"error": {
"code": "gone",
"message": "expired_token"
}
}
Example
# Poll every 5 seconds
curl -X POST "https://api.danubeai.com/v1/auth/device/token" \
-H "Content-Type: application/json" \
-d '{"device_code": "dc_a1b2c3d4e5f6..."}'
{
"api_key": "3q2xJd0eK9mPzV5tR8wYs1uB4nC7fH6gLsA2iDoXk5U",
"key_prefix": "3q2xJd0e"
}
Polling Logic
import time, requests
# Step 1: Get device code
resp = requests.post("https://api.danubeai.com/v1/auth/device/code",
json={"client_name": "My Agent"})
data = resp.json()
print(f"Enter code {data['user_code']} at {data['verification_url']}")
# Step 2: Poll for token
while True:
time.sleep(data["interval"])
poll = requests.post("https://api.danubeai.com/v1/auth/device/token",
json={"device_code": data["device_code"]})
if poll.status_code == 200:
api_key = poll.json()["api_key"]
print(f"Authorized! API key: {api_key[:12]}...")
break
elif poll.status_code == 428:
continue # Still waiting
else:
print("Code expired, start over")
break
