---
title: "生成 Discord 链接"
canonical_url: "https://tweetstream.io/zh-cn/docs/api/issue-agent-discord-link"
last_updated: 2026-11-05
---

# 生成 Discord 链接

生成一个 Discord 链接，对方打开后可关联 Discord 并加入 TweetStream 社区。部分结账要求先完成这一步再付款，状态查询会说明何时需要。

Canonical URL: https://tweetstream.io/zh-cn/docs/api/issue-agent-discord-link

## `POST /api/agent/discord-link`

`https://tweetstream.io/api/agent/discord-link`

## 授权

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `Authorization` | `string`, 必填 | 使用 TweetStream API 密钥进行 Bearer 认证：`Bearer <key>`。 |

## 请求头

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `X-TweetStream-Setup-Proof` | `string`, 必填 | 邮箱验证返回的 setupProof，有效期 30 分钟。过期后需重新验证邮箱验证码。 |

## 请求体

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `family` | `enum<string>`, 必填 |  |

### 请求体示例

```json
{
  "family": "BASE"
}
```

## 响应字段

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `checkoutId` | `string` | a string matching the pattern ^pl_[a-z0-9]{1,64}$ |
| `family` | `enum<string>`, 必填 |  |
| `next` | `object`, 必填 |  |
| `next.message` | `string` | a string at most 500 character(s) long |
| `next.action` | `enum<string>`, 必填 |  |
| `next.method` | `enum<string>`, 必填 |  |
| `next.url` | `string`, 必填 | a string matching the pattern ^(https\|wss):\/\/[^\s]+$ |
| `next.who` | `enum<string>`, 必填 |  |
| `offer` | `object` |  |
| `offer.amountDueNow` | `object`, 必填 |  |
| `offer.amountDueNow.currency` | `enum<string>`, 必填 |  |
| `offer.amountDueNow.minor` | `string`, 必填 | a string matching the pattern ^(0\|[1-9][0-9]*)$ |
| `offer.mode` | `enum<string>`, 必填 |  |
| `offer.planName` | `string`, 必填 |  |
| `offer.renewal` | `object`, 必填 |  |
| `offer.renewal.amount` | `object`, 必填 |  |
| `offer.renewal.amount.currency` | `enum<string>`, 必填 |  |
| `offer.renewal.amount.minor` | `string`, 必填 | a string matching the pattern ^(0\|[1-9][0-9]*)$ |
| `offer.renewal.at` | `string`, 必填 | a string to be decoded into a Date |
| `offer.renewal.billingCycle` | `enum<string>`, 必填 |  |
| `offer.renewal.thenAmount` | `object`, 必填 |  |
| `offer.renewal.thenAmount.currency` | `enum<string>`, 必填 |  |
| `offer.renewal.thenAmount.minor` | `string`, 必填 | a string matching the pattern ^(0\|[1-9][0-9]*)$ |
| `paymentUrl` | `string` | a string matching the pattern ^(https\|wss):\/\/[^\s]+$ |
| `reason` | `enum<string>`, 必填 |  |
| `status` | `enum<string>`, 必填 |  |
| `discord` | `object`, 必填 |  |
| `discord.expiresAt` | `string`, 必填 | a string to be decoded into a Date |
| `discord.required` | `boolean`, 必填 | Whether the open checkout waits for the person to join before it can be paid. |
| `discord.url` | `string`, 必填 | a string matching the pattern ^(https\|wss):\/\/[^\s]+$ |

## 响应

| 状态 | 说明 | 请求头 |
| --- | --- | --- |
| `200` | 成功 |  |
| `400` | 请求无效、验证码错误，或未接受服务条款 |  |
| `401` | API key 缺失或无效，或 setup proof 缺失或已过期 |  |
| `403` | 账号受到限制，或请求带有外部 Origin |  |
| `404` | 结账或链接不存在，或账号没有该产品的使用权 |  |
| `429` | 已达到速率限制或开通额度，请在 retryAfterSeconds 秒后重试 |  |
| `503` | 暂时不可用，请稍后重试 |  |

### 200

```json
{
  "status": "community_required",
  "family": "BASE",
  "reason": "COMMUNITY_REQUIRED",
  "checkoutId": "pl_8k2m4q7x",
  "discord": {
    "url": "https://tweetstream.io/connect/discord/EXAMPLE_DISCORD_LINK",
    "expiresAt": "2026-10-29T13:00:00.000Z",
    "required": true
  },
  "next": {
    "action": "join_discord",
    "who": "human",
    "url": "https://tweetstream.io/connect/discord/EXAMPLE_DISCORD_LINK",
    "pollUrl": "https://tweetstream.io/api/agent/status?checkoutId=pl_8k2m4q7x",
    "afterSeconds": 5
  }
}
```

### 400

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

### 401

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

### 403

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

### 404

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

### 429

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

### 503

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

## 代码示例

### cURL

```bash
curl --request POST \
  --url https://tweetstream.io/api/agent/discord-link \
  --header "Authorization: Bearer $TWEETSTREAM_API_KEY" \
  --header "X-TweetStream-Setup-Proof: $TWEETSTREAM_SETUP_PROOF" \
  --header 'Content-Type: application/json' \
  --data '{
  "family": "BASE"
}'
```

### JavaScript

```javascript
const response = await fetch("https://tweetstream.io/api/agent/discord-link", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.TWEETSTREAM_API_KEY}`,
    "X-TweetStream-Setup-Proof": process.env.TWEETSTREAM_SETUP_PROOF,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "family": "BASE"
  }),
});

console.log(response.status, await response.json());
```

### Python

```python
import os
import requests

response = requests.post(
    "https://tweetstream.io/api/agent/discord-link",
    headers={"Authorization": f"Bearer {os.environ['TWEETSTREAM_API_KEY']}", "X-TweetStream-Setup-Proof": os.environ["TWEETSTREAM_SETUP_PROOF"]},
    json={
        "family": "BASE",
    },
)

print(response.status_code, response.json())
```
