# Poll a CLI device login

- **OpenAPI Version:** `3.2.0`
- **API Version:** `3.1.0`
- **Contact:** Syndai <https://syndai.ai>

## Contents

**Operations**

- [POST /api/v1/cli/device/token](#scalar-operation-post-apiv1clidevicetoken)

**Schemas**

- [CliDeviceTokenRequest](#scalar-schema-clidevicetokenrequest)
- [CliDeviceTokenResponse](#scalar-schema-clidevicetokenresponse)
- [CliDeviceTokenError](#scalar-schema-clidevicetokenerror)
- [ProblemDetail](#scalar-schema-problemdetail)
- [ExternalErrorCode](#scalar-schema-externalerrorcode)

<a id="scalar-context-global-servers"></a>

## Servers

- **URL:** `https://api.syndai.ai`

<a id="scalar-context-global-authentication"></a>

## Authentication

- **CustomerApiKey**: HTTP bearer (`API Key`)

  Customer API key sent as a bearer token

## Tags

### CLI auth

The device login the `syndai` CLI uses to get an API key: start a login, show the user code to a person to approve in the browser, then poll for the key. Unapproved polls answer with OAuth device-flow errors.

## Operations

<a id="scalar-operation-post-apiv1clidevicetoken"></a>

### Poll a CLI device login

- **Method:** `POST`
- **Path:** `/api/v1/cli/device/token`
- **Operation ID:** `redeemCliDevice`
- **Tags:** CLI auth

Poll with the `device_code` from the login request, no more often than `interval` seconds. Returns 400 with `error` until the login is approved, then 200 with a new API key that expires after 90 days. The key is returned once: the code is spent and a later poll gets `expired_token`. No authentication is required.

**Servers:** [Inherited servers](#scalar-context-global-servers)

#### Authentication

No authentication required.

#### Request body

**Required:** `true`

**Content type:** `application/json`

[CliDeviceTokenRequest](#scalar-schema-clidevicetokenrequest)

<a id="scalar-example-1"></a>

**Generated example:**

```json
{
  "device_code": ""
}
```

#### Responses

##### 200 Request fulfilled, document follows

**Content type:** `application/json`

[CliDeviceTokenResponse](#scalar-schema-clidevicetokenresponse)

<a id="scalar-example-2"></a>

**Generated example:**

```json
{
  "api_key": "",
  "customer_id": "",
  "expires_at": "",
  "key_id": ""
}
```

##### 400 Not yet, or never: \`authorization\_pending\`, \`slow\_down\` (wait 5 s longer), \`access\_denied\` or \`expired\_token\` (RFC 8628 §3.5)

**Content type:** `application/json`

[CliDeviceTokenError](#scalar-schema-clidevicetokenerror)

<a id="scalar-example-3"></a>

**Generated example:**

```json
{
  "error": ""
}
```

##### 404, 426, 503

- `404` Resource not found
- `426` CLI\_UPGRADE\_REQUIRED: run npx -y syndai\@latest
- `503` CLI sign-in is unavailable right now

**Content type:** `application/problem+json`

[ProblemDetail](#scalar-schema-problemdetail)

RFC 7807 problem detail returned for public CaaS errors.

<a id="scalar-example-4"></a>

**Generated example:**

```json
{
  "code": "BUDGET_EXHAUSTED",
  "detail": null,
  "existing_run_id": null,
  "instance": null,
  "status": 1,
  "title": "",
  "type": "about:blank",
  "additionalProperty": "anything"
}
```

##### 429 Rate limit exceeded

**Headers:**

- **`Retry-After`**

  Seconds to wait before retrying the request

  `integer`

**Content type:** `application/problem+json`

[ProblemDetail](#scalar-schema-problemdetail)

RFC 7807 problem detail returned for public CaaS errors.

[Generated example](#scalar-example-4)

##### default Unexpected error

**Content type:** `application/problem+json`

[ProblemDetail](#scalar-schema-problemdetail)

<a id="scalar-example-5"></a>

**Generated example:**

```json
null
```

## Schemas

<a id="scalar-schema-clidevicetokenrequest"></a>

### CliDeviceTokenRequest

**Type:** `object`

- **`device_code` (required)**: `string`, minLength: `1`, maxLength: `200`

<a id="scalar-example-6"></a>

**Generated example:**

```json
{
  "device_code": ""
}
```

<a id="scalar-schema-clidevicetokenresponse"></a>

### CliDeviceTokenResponse

**Type:** `object`

- **`api_key` (required)**: `string`, format: `password`
- **`customer_id` (required)**: `string`, format: `uuid`
- **`expires_at` (required)**: `string`, format: `date-time`
- **`key_id` (required)**: `string`, format: `uuid`

<a id="scalar-example-7"></a>

**Generated example:**

```json
{
  "api_key": "",
  "customer_id": "",
  "expires_at": "",
  "key_id": ""
}
```

<a id="scalar-schema-clidevicetokenerror"></a>

### CliDeviceTokenError

**Type:** `object`

- **`error` (required)**: `string`

<a id="scalar-example-8"></a>

**Generated example:**

```json
{
  "error": ""
}
```

<a id="scalar-schema-problemdetail"></a>

### ProblemDetail

**Type:** `object`

RFC 7807 problem detail returned for public CaaS errors.

- **`code` (required)**: `string`, possible values: `"BUDGET_EXHAUSTED", "QUOTA_EXCEEDED", "RUN_CONCURRENCY_LIMIT", "CUSTOMER_DISABLED", "REPO_NOT_BOUND", "IDEMPOTENCY_REPLAY", "CONFLICT", "MISSION_BUSY_RETRY", "HITL_REQUEST_CONFLICT", "HITL_REQUEST_SETTLED", "RUN_TERMINATED_BEFORE_RESPONSE", "INVALID_POLICY", "INVALID_SCOPE", "RATE_LIMITED", "INSTALLATION_INCOMPLETE", "SUBSCRIPTION_USAGE_UNAVAILABLE", "INVALID_TOKEN", "ROLE_REQUIRED", "PLAN_UPGRADE_REQUIRED", "EMAIL_MISMATCH", "EXPIRED_TOKEN", "NOT_FOUND", "OVERSCOPE_ACK_REQUIRED", "VERIFY_FAILED", "PUBLISH_IN_FLIGHT", "PUBLISH_UNSUPPORTED_REPO", "PUBLICATION_NOT_LIVE", "NO_APP_DATA", "FEATURE_REQUESTS_NEEDS_MEMBERS", "EMPTY_UPDATE", "BAD_CURSOR", "HUMAN_APPROVAL_REQUIRED", "PROTECTED_PATHS_MANAGED_ONLY", "RUN_IN_FLIGHT", "TEXT_EDIT_REFUSED", "CLI_UPGRADE_REQUIRED", "PRODUCTION_STEP_UP_REQUIRED", "PRICES_UPDATING", "GITHUB_UNAVAILABLE", "PUBLISH_NOT_SET_UP", "VERSION_NOT_DEPLOYED", "INTERNAL_ERROR"`

  Stable error codes surfaced to public CaaS clients.
- **`status` (required)**: `integer`
- **`title` (required)**: `string`
- **`detail`**: `string | null`, default: `null`
- **`existing_run_id`**: `string | null`, default: `null`
- **`instance`**: `string | null`, default: `null`
- **`type`**: `string`, default: `"about:blank"`

<a id="scalar-example-9"></a>

**Generated example:**

```json
{
  "code": "BUDGET_EXHAUSTED",
  "detail": null,
  "existing_run_id": null,
  "instance": null,
  "status": 1,
  "title": "",
  "type": "about:blank",
  "additionalProperty": "anything"
}
```

<a id="scalar-schema-externalerrorcode"></a>

### ExternalErrorCode

**Type:** `string`, possible values: `"BUDGET_EXHAUSTED", "QUOTA_EXCEEDED", "RUN_CONCURRENCY_LIMIT", "CUSTOMER_DISABLED", "REPO_NOT_BOUND", "IDEMPOTENCY_REPLAY", "CONFLICT", "MISSION_BUSY_RETRY", "HITL_REQUEST_CONFLICT", "HITL_REQUEST_SETTLED", "RUN_TERMINATED_BEFORE_RESPONSE", "INVALID_POLICY", "INVALID_SCOPE", "RATE_LIMITED", "INSTALLATION_INCOMPLETE", "SUBSCRIPTION_USAGE_UNAVAILABLE", "INVALID_TOKEN", "ROLE_REQUIRED", "PLAN_UPGRADE_REQUIRED", "EMAIL_MISMATCH", "EXPIRED_TOKEN", "NOT_FOUND", "OVERSCOPE_ACK_REQUIRED", "VERIFY_FAILED", "PUBLISH_IN_FLIGHT", "PUBLISH_UNSUPPORTED_REPO", "PUBLICATION_NOT_LIVE", "NO_APP_DATA", "FEATURE_REQUESTS_NEEDS_MEMBERS", "EMPTY_UPDATE", "BAD_CURSOR", "HUMAN_APPROVAL_REQUIRED", "PROTECTED_PATHS_MANAGED_ONLY", "RUN_IN_FLIGHT", "TEXT_EDIT_REFUSED", "CLI_UPGRADE_REQUIRED", "PRODUCTION_STEP_UP_REQUIRED", "PRICES_UPDATING", "GITHUB_UNAVAILABLE", "PUBLISH_NOT_SET_UP", "VERSION_NOT_DEPLOYED", "INTERNAL_ERROR"`

Stable error codes surfaced to public CaaS clients.
