> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apistable.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 发起第一条请求

> 选择模型、提交任务并读取结果。

## 当前可用范围

本页介绍共用的异步任务 API。请从模型文档选择模型，并在提交前确认其可用状态。文档示例不代表能力已启用；未启用模型返回 HTTP 503，不创建任务或扣除积分。LLM 请求使用独立的 Chat Completions 接口。

## 1. 创建 API Key

* 在控制台 → API Keys 创建密钥，仅在服务端保存。

```bash theme={null}
export APISTABLE_API_KEY="YOUR_API_KEY"
```

[管理 API Key](https://apistable.ai/console/keys)

## 2. 选择模型

查看所选模型的文档，使用其模型 ID、必填参数和结果格式。参数、结果数量和结果字段因模型而异，不要直接套用其他模型的请求；标记暂未接入的分类不可提交任务。

[模型市场](https://apistable.ai/models)

## 3. 提交任务

model 使用所选模型 ID，将按模型文档构造的 input 对象保存为 input.json。下面命令通过 jq 构造请求，运行前需安装 jq。仅在模型支持时，才在 input 内传 output\_count 或 fallback。

```bash theme={null}
jq -n --arg model 'YOUR_MODEL_ID' --slurpfile input input.json \
  '{model: $model, input: $input[0]}' > request.json

curl --request POST 'https://apistable.ai/api/v1/tasks/create_task' \
  --header "Authorization: Bearer $APISTABLE_API_KEY" \
  --header 'Content-Type: application/json' \
  --data @request.json
```

[创建任务接口](https://docs.apistable.ai/zh/create-task.md)

## 4. 保存任务 ID

受理成功返回 HTTP 200 和 data.task\_id，受理不等于生成完成。保存这个 APIstable ID，后续查询同一任务。如果提交超时且无法确认是否受理，不要自动重新提交。

```json theme={null}
{
  "code": 200,
  "msg": "success",
  "data": {
    "task_id": "YOUR_TASK_ID"
  }
}
```

## 5. 查询直到任务结束

将 YOUR\_TASK\_ID 替换为受理时返回的任务 ID。data.status 为 processing 时，间隔一段时间继续查询；succeeded 或 failed 时停止。失败原因查看 data.message；成功前 result 为 null。

```bash theme={null}
curl 'https://apistable.ai/api/v1/tasks/YOUR_TASK_ID' \
  --header "Authorization: Bearer $APISTABLE_API_KEY"
```

[任务查询响应字段](https://docs.apistable.ai/zh/query-task.md)

## 6. 读取并保存结果

* HTTP 响应只解析一次。response.data.result 成功时已是对象，处理中或失败时为 null；只有任务 input 字段仍为 JSON 字符串。
* 按所选模型的 结果格式说明读取 result，不要假定所有模型返回相同字段或相同数量的产物。请在文档规定的有效期内保存返回的文件。
* 任务结束后，从 data.charged\_credits 读取最终实扣积分。查询成功不代表任务成功，还需检查 data.status。

[结果 JSON 指南](https://docs.apistable.ai/zh/outputs.md)

## 可选：接收回调

创建任务时可传公网 HTTPS callback\_url，并从控制台 → 账户设置 → Webhook 安全复制签名密钥。处理回调前须验证签名并按事件去重；正文按所选模型的回调契约解析，漏收时查询任务。

[回调签名与投递](https://docs.apistable.ai/zh/webhooks.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.