# Complete a ChatGPT plan sign-in in the initiating browser session.

> https://koi.dog/docs/api/connections/complete-codex-sign-in/

`POST /api/v1/codex-connection/complete` · Key: `session only`

Use the `koidog_session` cookie at `https://app.koi.dog/api/v1` with `Origin: https://app.koi.dog`.

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Retry the same request with the same key. [Retry rules](https://koi.dog/docs/api/#retries). |

## Body.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `state` | `string` | yes | The state returned from the sign-in attempt in the same browser session. Matches `^[a-zA-Z0-9_-]{43}$`. |
| `code` | `string` | no | The authorization code returned by OpenAI after consent. 1 to 4096 characters. |
| `clientId` | `string` | no | The client identifier if OpenAI included one in its response. 1 to 256 characters. |
| `error` | `string` | no | The error returned by OpenAI if authorization failed. 1 to 80 characters. |

## Response.

200 OK · JSON object

- **422 validation_failed**: Each schema error appears in `details`.

## Request.

```sh
# The dashboard session only: an API key is refused (403 session_required).
curl -X POST https://app.koi.dog/api/v1/codex-connection/complete \
    -H "Cookie: koidog_session=$KOIDOG_SESSION" \
    -H "Origin: https://app.koi.dog" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{
      "state": "example_state_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "error": "access_denied"
    }'
```

```js
// The dashboard session only: an API key is refused (403 session_required).
const res = await fetch("https://app.koi.dog/api/v1/codex-connection/complete", {
  method: "POST",
  headers: {
    Cookie: `koidog_session=${process.env.KOIDOG_SESSION}`,
    Origin: "https://app.koi.dog",
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    state: "example_state_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    error: "access_denied",
  }),
});
console.log(await res.json());
```

```python
import os
import uuid

import requests

# The dashboard session only: an API key is refused (403 session_required).
r = requests.post(
    "https://app.koi.dog/api/v1/codex-connection/complete",
    headers={
        "Cookie": f"koidog_session={os.environ['KOIDOG_SESSION']}",
        "Origin": "https://app.koi.dog",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "state": "example_state_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "error": "access_denied",
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "status": "connected"
}
```
