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

# Request Device Code

Start the device authorization flow. The CLI or MCP server calls this endpoint to get a device code and user code.

**No authentication required.** This is a public endpoint.

## Flow

1. Client calls this endpoint to get codes
2. User visits the `verification_uri` and enters the `user_code`
3. Client polls [`/v1/auth/device/token`](/api-reference/auth/device-token) until user approves

User codes use the format `XXXX-XXXX` with an unambiguous alphabet (no 0/O, 1/I/l confusion).

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.v2.dealmachine.com/v1/auth/device/code \
    -H "Content-Type: application/json" \
    -d '{
      "client_id": "dealmachine-next-cli",
      "device_name": "MacBook Pro"
    }'
  ```

  ```typescript Node.js theme={null}
  const response = await fetch('https://api.v2.dealmachine.com/v1/auth/device/code', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      client_id: 'dealmachine-next-cli',
      device_name: 'MacBook Pro',
    }),
  });

  const data = await response.json();
  console.log(`Enter code: ${data.user_code}`);
  console.log(`Visit: ${data.verification_uri}`);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.v2.dealmachine.com/v1/auth/device/code',
      json={
          'client_id': 'dealmachine-next-cli',
          'device_name': 'MacBook Pro'
      }
  )

  data = response.json()
  print(f"Enter code: {data['user_code']}")
  print(f"Visit: {data['verification_uri']}")
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "device_code": "a1b2c3d4e5f6...",
    "user_code": "BCDF-GHJK",
    "verification_uri": "https://dm-next.dealmachine.com/device/authorize",
    "verification_uri_complete": "https://dm-next.dealmachine.com/device/authorize?code=BCDF-GHJK",
    "expires_in": 2592000,
    "interval": 5
  }
  ```

  ```json 400 Invalid Client theme={null}
  {
    "error": {
      "code": "invalid_request",
      "message": "Invalid client_id. Must be one of: dealmachine-next-cli, dealmachine-next-mcp",
      "request_id": "req_abc123"
    }
  }
  ```
</ResponseExample>

## Request Body

| Field         | Type   | Required | Description                                                         |
| ------------- | ------ | -------- | ------------------------------------------------------------------- |
| `client_id`   | string | Yes      | Client identifier: `dealmachine-next-cli` or `dealmachine-next-mcp` |
| `device_name` | string | No       | Friendly name for the device (e.g., "MacBook Pro")                  |

## Response Fields

| Field                       | Type   | Description                                  |
| --------------------------- | ------ | -------------------------------------------- |
| `device_code`               | string | Secret code for polling (don't show to user) |
| `user_code`                 | string | Code for user to enter (XXXX-XXXX format)    |
| `verification_uri`          | string | URL for user to visit                        |
| `verification_uri_complete` | string | URL with code pre-filled                     |
| `expires_in`                | number | Seconds until codes expire (30 days)         |
| `interval`                  | number | Minimum seconds between poll requests        |
