# 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": "dk_a1b2c3d4e5f6g7h8i9j0...", "key_prefix": "dk_a1b2c" }
Poll for an API key after device code authorization
interval
device_code
dk_abc123...
{ "detail": "authorization_pending" }
{ "detail": "expired_token" }
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