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

# HTTP 与 cURL

> 直接发送 JSON 请求并读取返回结果。

需要 cURL 7.76+，命令适用于 Bash / Zsh。先设置[环境变量](/zh/guides/api-basics)。

## Chat Completions

将下面内容保存为 `request.json`，把 `YOUR_MODEL_ID` 替换为支持对话的真实模型 ID：

```json theme={null}
{
  "model": "YOUR_MODEL_ID",
  "messages": [{ "role": "user", "content": "Say hello in one short sentence." }]
}
```

```bash theme={null}
curl --fail-with-body --silent --show-error --max-time 60 \
  "$API_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  --data-binary @request.json
```

成功时读取 `choices[0].message.content`。工具调用时文本可能为空，应检查 `tool_calls` 和 `finish_reason`。

## Responses

确认模型支持 Responses 后，将 `request.json` 改为以下内容，再请求 `/responses`：

```json theme={null}
{
  "model": "YOUR_MODEL_ID",
  "input": "Say hello in one short sentence."
}
```

```bash theme={null}
curl --fail-with-body --silent --show-error --max-time 60 \
  "$API_BASE_URL/responses" \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  --data-binary @request.json
```

先检查 `status`。文本位于 `output` 中 `type=message` 项的 `content` 数组内，读取 `type=output_text` 的 `text`。原始 HTTP JSON 不保证存在顶层 `output_text`；该属性是 SDK 提供的便利字段。

## 请求与结果

`--fail-with-body` 在 HTTP 错误时保留响应体并以非零状态退出；`--max-time 60` 是本例的客户端超时，不是服务端处理时限。超时不代表上游未执行，不要立即重复提交。

流式调用需要在 JSON 中加入 `"stream": true`，并给 cURL 加 `--no-buffer`。按[流式输出](/zh/guides/streaming)处理 SSE，而不是对整段响应调用 JSON 解析。

[查看错误排查](/zh/guides/errors)

[Read in English](/en/guides/http)


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