# POST /api/auth/sessions/exchange

Canonical URL: https://developers.iagenify.com/api/auth/sessions-exchange/
Language: en

`POST https://api.iagenify.com/api/auth/sessions/exchange`

Exchange an API key for a bearer session. Use the returned bearer token on protected API requests and retain the refresh token only in trusted server-side storage.

Status: no bearer token required · JSON · session exchange

## HTTP request {#http}

```bash
curl https://api.iagenify.com/api/auth/sessions/exchange \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"apiKey":"YOUR_API_KEY"}'
```

## JavaScript {#javascript}

```javascript
const response = await fetch("https://api.iagenify.com/api/auth/sessions/exchange", {
  method: "POST", headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ apiKey: process.env.IAGENIFY_API_KEY }),
});
const session = await response.json();
if (!response.ok) throw new Error(session.error);
// Store session.jwt and session.refreshToken only in trusted storage.
```

## Python {#python}

```python
import os, requests

response = requests.post(
    "https://api.iagenify.com/api/auth/sessions/exchange",
    json={"apiKey": os.environ["IAGENIFY_API_KEY"]},
    timeout=30,
)
response.raise_for_status()
session = response.json()
```

## Request body {#body}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `apiKey` | string | required | The API key to exchange. |
| `storageId` | string |  | Optional storage association. |
| `storageType` | string |  | Optional client storage type. |
| `framework` | string |  | Optional client framework label. |
| `appName` | string |  | Optional application name. |

## Successful response {#response}

```javascript
{
  ok: true,
  jwt: "…",
  refreshToken: "…",
  session: { id: "…", storageId: "…" }
}
```

## Next request {#next}

Send the returned JWT as `Authorization: Bearer YOUR_JWT`. When it expires, use [POST /api/auth/refresh](/api/auth/refresh); never put either token in a URL or browser-delivered source.
