> ## Documentation Index
> Fetch the complete documentation index at: https://docs.danubeai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Poll Device Token

> Poll for an API key after device code authorization

## Overview

Polls for the result of a device authorization flow. The agent should call this endpoint every 5 seconds (the `interval` from the device code response) until it receives an API key or the code expires.

No authentication required.

## Body Parameters

<ParamField body="device_code" type="string" required>
  The `device_code` returned by [Create Device Code](/api-reference/endpoint/create_device_code)
</ParamField>

## Response

### Success (200) — User has authorized

<ResponseField name="api_key" type="string">
  The API key to use for future requests (e.g., `dk_abc123...`)
</ResponseField>

<ResponseField name="key_prefix" type="string">
  First 8 characters of the key
</ResponseField>

### Pending (428) — User hasn't authorized yet

```json theme={null}
{
  "detail": "authorization_pending"
}
```

Keep polling every `interval` seconds.

### Expired (410) — Code has expired or been used

```json theme={null}
{
  "detail": "expired_token"
}
```

Start a new flow with [Create Device Code](/api-reference/endpoint/create_device_code).

## Example

<RequestExample>
  ```bash cURL theme={null}
  # 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..."}'
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "api_key": "dk_a1b2c3d4e5f6g7h8i9j0...",
    "key_prefix": "dk_a1b2c"
  }
  ```
</ResponseExample>

## Polling Logic

```python theme={null}
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
```
