---
title: "Exchange an email code"
description: "Exchanges the six-digit email code for a bearer access token and refresh token."
canonical: "https://www.cool.computer/docs/api-reference/authentication/exchange-an-email-code"
---
# Exchange an email code

> Exchanges the six-digit email code for a bearer access token and refresh token.

```http
POST https://api.cool.computer/api/auth/email/complete
```

Exchanges the six-digit email code for a bearer access token and refresh token. Each email gets at most 5 codes sent and 10 codes tried in 10 minutes, counted together with the SSH sign-in prompt by each API process; past that this answers 429 rate_limited with Retry-After, the seconds until the email may try again.

## Authorization

No credential is needed.

## Request body

Required.

- `application/json` (object)
  - `email` (string, email, required)
  - `code` (string, pattern `^[0-9]{6}$`, required)

## Responses

- `200`: Bearer and refresh credentials for the account.
  - `application/json` (object)
    - `access_token` (string, required): A short-lived user access token. For repeated automation, create an API key with it (POST /api/api-keys) instead of refreshing it in a loop.
    - `expires_in` (integer, at least 0, required): Seconds until access_token expires, from its exp claim. Refresh it with POST /api/auth/refresh before then.
    - `refresh_token` (string, required)
    - `organization_id` (string, required)
    - `session_id` (string, required)
- `400`: Bad Request.
- `401`: Unauthorized.
- `403`: Forbidden. `sign_up_waitlisted` means Cool Computers is full right now and this email has no account and no invitation, so it joined the waitlist. Stop: signing up again with the same email works once the invitation email arrives, or later once there is room.
- `413`: Payload Too Large.
- `429`: Too Many Requests. If the problem code is api_request_rate_exceeded, wait for Retry-After seconds; other problem codes describe a separate limit.
- `500`: Internal Server Error.
- `503`: Service Unavailable.
- `default`: A machine-readable API error with a stable code and recovery instruction.

An error is an `application/problem+json` document with a stable `code`; [API errors](/docs/api-reference/errors) says how to handle one.

## Example

```sh
curl -X POST "https://api.cool.computer/api/auth/email/complete" \
  -H "content-type: application/json" \
  --data '{"email":"ana@example.com","code":"123456"}'
```
