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

# Responses

> 使用 OpenAI Responses 格式调用模型，Codex 使用的就是这个接口。

```text theme={null}
POST https://www.jiji.cc/v1/responses
```

Responses 是 OpenAI 推荐的新接口，Codex 也使用这个接口。相比 Chat Completions，它对推理模型、工具调用和多轮对话的支持更完整。

## 基础调用

<CodeGroup>
  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      base_url="https://www.jiji.cc/v1",
      api_key=os.environ["JIJI_API_KEY"],
  )

  resp = client.responses.create(
      model="gpt-6.1-sol",
      instructions="你是一个简洁的编程助手。",
      input="用一句话解释什么是闭包。",
  )
  print(resp.output_text)
  ```

  ```javascript Node.js theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: "https://www.jiji.cc/v1",
    apiKey: process.env.JIJI_API_KEY,
  });

  const resp = await client.responses.create({
    model: "gpt-6.1-sol",
    instructions: "你是一个简洁的编程助手。",
    input: "用一句话解释什么是闭包。",
  });
  console.log(resp.output_text);
  ```

  ```bash cURL theme={null}
  curl https://www.jiji.cc/v1/responses \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $JIJI_API_KEY" \
    -d '{
      "model": "gpt-6.1-sol",
      "instructions": "你是一个简洁的编程助手。",
      "input": "用一句话解释什么是闭包。"
    }'
  ```
</CodeGroup>

## 控制思考强度

通过 `reasoning.effort` 控制推理模型的思考深度。思考越深，效果越好，但耗时和 Token 消耗也越多：

```python Python theme={null}
resp = client.responses.create(
    model="gpt-6.1-sol",
    reasoning={"effort": "high"},
    input="设计一个支持撤销和重做的文本编辑器数据结构。",
)
print(resp.output_text)
```

| 取值 | 适合场景 |
| - | - |
| `low` | 简单问答、格式转换 |
| `medium` | 日常编程任务 |
| `high` | 复杂设计、疑难 bug |
| `xhigh` | 最难的任务，耗时最长 |

<Note>
  不同模型支持的取值不完全相同，以模型实际返回为准。
</Note>

## 流式输出

```python Python theme={null}
stream = client.responses.create(
    model="gpt-6.1-sol",
    input="写一首关于春天的短诗",
    stream=True,
)
for event in stream:
    if event.type == "response.output_text.delta":
        print(event.delta, end="", flush=True)
```

## 多轮对话

把历史消息放进 `input` 列表：

```python Python theme={null}
history = [{"role": "user", "content": "我叫小明"}]
resp = client.responses.create(model="gpt-6.1-sol", input=history)

history += resp.output
history.append({"role": "user", "content": "我叫什么名字？"})
resp = client.responses.create(model="gpt-6.1-sol", input=history)
print(resp.output_text)
```

<Note>
  建议在本地保存对话历史，每次请求完整传入，不要依赖 `previous_response_id` 让服务端保存上下文。
</Note>

## 工具调用

```python Python theme={null}
import json

tools = [{
    "type": "function",
    "name": "get_weather",
    "description": "查询城市的实时天气",
    "parameters": {
        "type": "object",
        "properties": {"city": {"type": "string"}},
        "required": ["city"],
    },
}]

history = [{"role": "user", "content": "北京今天天气怎么样？"}]
resp = client.responses.create(model="gpt-6.1-sol", input=history, tools=tools)

for item in resp.output:
    if item.type == "function_call":
        args = json.loads(item.arguments)
        result = {"city": args["city"], "weather": "晴", "temp": 22}  # 替换为真实查询
        history += resp.output
        history.append({
            "type": "function_call_output",
            "call_id": item.call_id,
            "output": json.dumps(result, ensure_ascii=False),
        })
        resp = client.responses.create(model="gpt-6.1-sol", input=history, tools=tools)

print(resp.output_text)
```


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