# POST /api/auth/sessions/exchange

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

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

交换a API 用于无记名会话的密钥。在受保护的状态下使用返回的无记名牌 API 请求并只将刷新牌保存在可信任的服务器端存储中。

Status: 无需 Bearer 令牌 · JSON · 会话交换

## HTTP 请求 {#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()
```

## 请求体 {#body}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `apiKey` | string | 必填 | 下 API 键交换。 |
| `storageId` | string |  | 任择储存协会。 |
| `storageType` | string |  | 客户可选存储类型。 |
| `framework` | string |  | 可选客户框架标签。 |
| `appName` | string |  | 任择申请姓名。 |

## 成功响应 {#response}

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

## 下个请求 {#next}

发送返回 JWT 年为 `Authorization: Bearer YOUR_JWT`。当它过期时,使用 [POST /api/auth/refresh](/zh/api/auth/refresh); 从来没有在 URL 或浏览器发送源。
