# Exchange a sign-in code for a session

`POST /v1/console/auth/session` (operation id `createSession`)

Sets the `__Host-dex_session` cookie and returns the CSRF token the console must send in `x-dex-csrf` on every state-changing console call.

Authentication: None. This route is public.

## Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `email` | string | yes | (format email; at most 254 characters) |
| `code` | string | yes | (pattern ^[0-9]{6}$) |

## Responses

### 200

Signed in.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | yes | (always "session") |
| `account_id` | AccountId | yes | (pattern ^acc_[0-9A-HJKMNP-TV-Z]{26}$) |
| `csrf_token` | string | yes |  |
| `expires_at` | string | yes | (format date-time) |

### 400

The request could not be read. Codes: `invalid_json` (not JSON, not UTF-8, or a `\u` escape that is half of a
surrogate pair, such as `"\ud800"` without its low half), `duplicate_key` (a JSON object
repeats a key; `param` is the JSON pointer of the repeated member, such as `/questions/q1/options/a`),
`unsupported_media_type` (not `application/json`) and `invalid_header` (a malformed `idempotency-key` or
`x-client-request-id`; `param` names the header).


### 401

The sign-in code did not work. Codes: `invalid_code` (the code is wrong or expired, or no code was asked for
this address) and `code_attempts_exceeded` (the code had 5 wrong tries and no longer works, the right code
included; ask for a new code).


### 422

The request is well-formed JSON but breaks a validation rule. `param` names the field as a dotted path.
Codes: `unknown_field`, `missing_field`, `invalid_type` (wrong JSON type), `invalid_value` (right type, value
out of range: an empty or over-long string, a state, `instructions`, `criteria` string or option description
of only whitespace, an empty `questions` or `options` object, an empty state object or array, a pattern or
allowed-value mismatch such as a label or level with outer whitespace, a state nested deeper than 32 levels, a
bad date or date range), `field_not_allowed` (`options` or `levels` on the wrong question type),
`invalid_question_id`, `too_many_questions`, `too_many_options`, `invalid_levels` (including two levels equal
after Unicode NFC normalisation and lower-casing), `invalid_min_confidence`, `duplicate_label` (two option
labels equal after Unicode NFC normalisation and lower-casing, such as `Billing` and `billing`),
`state_path_not_found`, `state_not_json` and, on the console, `top_up_limit_exceeded`.


### 429

A rate limit or quota is exhausted. Retry after the given number of seconds. For `test_daily_quota` that is
the time until 00:00 UTC; clients should not retry it automatically.


### 500

An unexpected error. Any charge was refunded. Retry with the same idempotency key.

### 503

`maintenance`: the console's database, sign-in or payments are unavailable for a moment. Retry after
`retry-after`. Nothing was changed.


## Examples

Illustrative values. Examples show the shape of requests and responses; the numbers in them are not measured results.

Request: code

```json
{
  "email": "dev@example.nl",
  "code": "482913"
}
```

Response: session

```json
{
  "object": "session",
  "account_id": "acc_01M4ZPXYG0F5KZNWJ47TAN9ZT2",
  "csrf_token": "c8f1b7e04a2d4c6f9e3a51d27b60f8a4",
  "expires_at": "2026-11-19T12:00:00Z"
}
```
