跳到主要內容
API 參考
API 參考

OpenAI Responses

透過 RunAPI 相容 OpenAI 的 Responses 操作傳送請求。

01

概覽

使用 RunAPI 的 OpenAI 相容「Responses」操作,搭配相容的模型及該協定的請求與回應格式。

快速入門

  1. 建立 API 金鑰並將其設定為 RUNAPI_API_KEY。
  2. 選擇相容的模型,然後傳送文件中指定的路徑參數與 JSON 本文。
  3. 讀取此操作顯示的 JSON 回應或伺服器傳送事件,並處理協定錯誤。

端點

POST /v1/responses
基礎 URL
https://runapi.ai
合約版本
v1
建議的身分驗證方式
Authorization: Bearer YOUR_API_TOKEN
02

身分驗證載體

RunAPI 接受以下列出的每種傳輸協定。產生的範例使用該協定偏好的標頭。

header - 建議
Authorization: Bearer YOUR_API_TOKEN
header
x-api-key: YOUR_API_TOKEN
header
x-goog-api-key: YOUR_API_TOKEN
query
?key=YOUR_API_TOKEN
03

相容模型

開啟模型頁面以查看目前的定價、速率限制及商業用途詳情。

顯示 58 個相容模型
04

請求合約

JSON 請求內文

僅列出同時具備公開協定與 RunAPI 支援依據的欄位。其他 JSON 本文欄位將直接傳遞。

JSON 主體13 個欄位
input["string", "array"]
選填

提供給模型的文字、訊息項目或工具結果。

instructions["string", "null"]
選填

此回應的系統或開發人員指令。

max_output_tokens["integer", "null"]
選填

最大輸出 token 數,包含可見 token 與推理 token。

modelstring
必填

由相容模型目錄回傳的 RunAPI 模型識別碼。

moderation["object", "null"]
選填

針對目前的輸入與完整輸出,回傳獨立的內容審核訊號。

moderation.modelstring
必填 允許的值: omni-moderation-latest
moderation.policy["object", "null"]
選填
moderation.policy.input["object", "null"]
選填
moderation.policy.input.modestring
必填 允許的值: score, block
moderation.policy.output["object", "null"]
選填
moderation.policy.output.modestring
必填 允許的值: score, block
stream["boolean", "null"]
選填

以伺服器傳送事件的形式回傳具型別的 Responses 事件。

預設值: false
toolsarray
選填

模型可呼叫的工具。

請求範例

JSON
{
  "input": "Summarize one practical improvement for an API deployment.",
  "model": "gpt-5.4",
  "moderation": {
    "model": "omni-moderation-latest",
    "policy": {
      "input": {
        "mode": "score"
      },
      "output": {
        "mode": "block"
      }
    }
  }
}
05

同步回應

HTTP 200

結構描述

JSON
{
  "additionalProperties": true,
  "properties": {
    "id": {
      "type": "string"
    },
    "model": {
      "type": "string"
    },
    "moderation": {
      "additionalProperties": true,
      "properties": {
        "input": {
          "oneOf": [
            {
              "additionalProperties": true,
              "properties": {
                "categories": {
                  "additionalProperties": true,
                  "type": "object"
                },
                "category_applied_input_types": {
                  "additionalProperties": true,
                  "type": "object"
                },
                "category_scores": {
                  "additionalProperties": true,
                  "type": "object"
                },
                "flagged": {
                  "type": "boolean"
                },
                "model": {
                  "const": "omni-moderation-latest",
                  "type": "string"
                },
                "type": {
                  "const": "moderation_result",
                  "type": "string"
                }
              },
              "required": [
                "type",
                "model",
                "flagged",
                "categories",
                "category_scores",
                "category_applied_input_types"
              ],
              "type": "object"
            },
            {
              "additionalProperties": true,
              "properties": {
                "code": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                },
                "type": {
                  "const": "error",
                  "type": "string"
                }
              },
              "required": [
                "type",
                "code",
                "message"
              ],
              "type": "object"
            }
          ]
        },
        "output": {
          "oneOf": [
            {
              "additionalProperties": true,
              "properties": {
                "categories": {
                  "additionalProperties": true,
                  "type": "object"
                },
                "category_applied_input_types": {
                  "additionalProperties": true,
                  "type": "object"
                },
                "category_scores": {
                  "additionalProperties": true,
                  "type": "object"
                },
                "flagged": {
                  "type": "boolean"
                },
                "model": {
                  "const": "omni-moderation-latest",
                  "type": "string"
                },
                "type": {
                  "const": "moderation_result",
                  "type": "string"
                }
              },
              "required": [
                "type",
                "model",
                "flagged",
                "categories",
                "category_scores",
                "category_applied_input_types"
              ],
              "type": "object"
            },
            {
              "additionalProperties": true,
              "properties": {
                "code": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                },
                "type": {
                  "const": "error",
                  "type": "string"
                }
              },
              "required": [
                "type",
                "code",
                "message"
              ],
              "type": "object"
            }
          ]
        }
      },
      "required": [
        "input",
        "output"
      ],
      "type": "object"
    },
    "object": {
      "const": "response",
      "type": "string"
    },
    "output": {
      "type": "array"
    },
    "status": {
      "type": "string"
    },
    "usage": {
      "additionalProperties": true,
      "properties": {
        "input_tokens": {
          "type": "integer"
        },
        "output_tokens": {
          "type": "integer"
        },
        "total_tokens": {
          "type": "integer"
        }
      },
      "required": [
        "input_tokens",
        "output_tokens",
        "total_tokens"
      ],
      "type": "object"
    }
  },
  "required": [
    "id",
    "object",
    "status",
    "model",
    "output"
  ],
  "type": "object"
}

範例

JSON
{
  "id": "resp_example",
  "model": "gpt-5.4",
  "moderation": {
    "input": {
      "categories": {
        "sexual": false,
        "violence": true
      },
      "category_applied_input_types": {
        "sexual": [
          "text"
        ],
        "violence": [
          "text"
        ]
      },
      "category_scores": {
        "sexual": 0.0002,
        "violence": 0.96
      },
      "flagged": true,
      "model": "omni-moderation-latest",
      "type": "moderation_result"
    },
    "output": {
      "categories": {
        "sexual": false,
        "violence": false
      },
      "category_applied_input_types": {
        "sexual": [
          "text"
        ],
        "violence": [
          "text"
        ]
      },
      "category_scores": {
        "sexual": 0.0002,
        "violence": 0.0001
      },
      "flagged": false,
      "model": "omni-moderation-latest",
      "type": "moderation_result"
    }
  },
  "object": "response",
  "output": [
    {
      "content": [
        {
          "annotations": [],
          "text": "Hello! How can I help today?",
          "type": "output_text"
        }
      ],
      "id": "msg_example",
      "role": "assistant",
      "status": "completed",
      "type": "message"
    }
  ],
  "status": "completed",
  "usage": {
    "input_tokens": 12,
    "output_tokens": 8,
    "total_tokens": 20
  }
}
06

SSE 事件:output_text_delta

text/event-stream

結構描述

JSON
{
  "additionalProperties": true,
  "properties": {
    "content_index": {
      "type": "integer"
    },
    "delta": {
      "type": "string"
    },
    "item_id": {
      "type": "string"
    },
    "output_index": {
      "type": "integer"
    },
    "type": {
      "const": "response.output_text.delta",
      "type": "string"
    }
  },
  "required": [
    "type",
    "item_id",
    "output_index",
    "content_index",
    "delta"
  ],
  "type": "object"
}

範例

JSON
{
  "content_index": 0,
  "delta": "Hello",
  "item_id": "msg_example",
  "output_index": 0,
  "type": "response.output_text.delta"
}
07

SSE 事件:completed

text/event-stream

結構描述

JSON
{
  "additionalProperties": true,
  "properties": {
    "response": {
      "additionalProperties": true,
      "properties": {
        "id": {
          "type": "string"
        },
        "model": {
          "type": "string"
        },
        "moderation": {
          "additionalProperties": true,
          "properties": {
            "input": {
              "oneOf": [
                {
                  "additionalProperties": true,
                  "properties": {
                    "categories": {
                      "additionalProperties": true,
                      "type": "object"
                    },
                    "category_applied_input_types": {
                      "additionalProperties": true,
                      "type": "object"
                    },
                    "category_scores": {
                      "additionalProperties": true,
                      "type": "object"
                    },
                    "flagged": {
                      "type": "boolean"
                    },
                    "model": {
                      "const": "omni-moderation-latest",
                      "type": "string"
                    },
                    "type": {
                      "const": "moderation_result",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "model",
                    "flagged",
                    "categories",
                    "category_scores",
                    "category_applied_input_types"
                  ],
                  "type": "object"
                },
                {
                  "additionalProperties": true,
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    },
                    "type": {
                      "const": "error",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "code",
                    "message"
                  ],
                  "type": "object"
                }
              ]
            },
            "output": {
              "oneOf": [
                {
                  "additionalProperties": true,
                  "properties": {
                    "categories": {
                      "additionalProperties": true,
                      "type": "object"
                    },
                    "category_applied_input_types": {
                      "additionalProperties": true,
                      "type": "object"
                    },
                    "category_scores": {
                      "additionalProperties": true,
                      "type": "object"
                    },
                    "flagged": {
                      "type": "boolean"
                    },
                    "model": {
                      "const": "omni-moderation-latest",
                      "type": "string"
                    },
                    "type": {
                      "const": "moderation_result",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "model",
                    "flagged",
                    "categories",
                    "category_scores",
                    "category_applied_input_types"
                  ],
                  "type": "object"
                },
                {
                  "additionalProperties": true,
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    },
                    "type": {
                      "const": "error",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "code",
                    "message"
                  ],
                  "type": "object"
                }
              ]
            }
          },
          "required": [
            "input",
            "output"
          ],
          "type": "object"
        },
        "object": {
          "const": "response",
          "type": "string"
        },
        "output": {
          "type": "array"
        },
        "status": {
          "type": "string"
        },
        "usage": {
          "additionalProperties": true,
          "properties": {
            "input_tokens": {
              "type": "integer"
            },
            "output_tokens": {
              "type": "integer"
            },
            "total_tokens": {
              "type": "integer"
            }
          },
          "required": [
            "input_tokens",
            "output_tokens",
            "total_tokens"
          ],
          "type": "object"
        }
      },
      "required": [
        "id",
        "object",
        "status",
        "model",
        "output",
        "usage"
      ],
      "type": "object"
    },
    "type": {
      "const": "response.completed",
      "type": "string"
    }
  },
  "required": [
    "type",
    "response"
  ],
  "type": "object"
}

範例

JSON
{
  "response": {
    "id": "resp_example",
    "model": "gpt-5.4",
    "moderation": {
      "input": {
        "categories": {
          "sexual": false,
          "violence": true
        },
        "category_applied_input_types": {
          "sexual": [
            "text"
          ],
          "violence": [
            "text"
          ]
        },
        "category_scores": {
          "sexual": 0.0002,
          "violence": 0.96
        },
        "flagged": true,
        "model": "omni-moderation-latest",
        "type": "moderation_result"
      },
      "output": {
        "categories": {
          "sexual": false,
          "violence": false
        },
        "category_applied_input_types": {
          "sexual": [
            "text"
          ],
          "violence": [
            "text"
          ]
        },
        "category_scores": {
          "sexual": 0.0002,
          "violence": 0.0001
        },
        "flagged": false,
        "model": "omni-moderation-latest",
        "type": "moderation_result"
      }
    },
    "object": "response",
    "output": [
      {
        "content": [
          {
            "annotations": [],
            "text": "Hello! How can I help today?",
            "type": "output_text"
          }
        ],
        "id": "msg_example",
        "role": "assistant",
        "status": "completed",
        "type": "message"
      }
    ],
    "status": "completed",
    "usage": {
      "input_tokens": 12,
      "output_tokens": 8,
      "total_tokens": 20
    }
  },
  "type": "response.completed"
}
08

協定錯誤:invalid_request

HTTP 400

結構描述

JSON
{
  "additionalProperties": true,
  "properties": {
    "error": {
      "additionalProperties": true,
      "properties": {
        "code": {
          "type": [
            "string",
            "null"
          ]
        },
        "message": {
          "type": "string"
        },
        "param": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": "string"
        }
      },
      "required": [
        "message",
        "type"
      ],
      "type": "object"
    }
  },
  "required": [
    "error"
  ],
  "type": "object"
}

範例

JSON
{
  "error": {
    "code": null,
    "message": "input must be a string or an array",
    "param": "input",
    "type": "invalid_request_error"
  }
}
09

用量

結構描述

JSON
{
  "additionalProperties": true,
  "properties": {
    "input_tokens": {
      "type": "integer"
    },
    "output_tokens": {
      "type": "integer"
    },
    "total_tokens": {
      "type": "integer"
    }
  },
  "required": [
    "input_tokens",
    "output_tokens",
    "total_tokens"
  ],
  "type": "object"
}

範例

JSON
{
  "input_tokens": 12,
  "output_tokens": 8,
  "total_tokens": 20
}
10

產生的程式碼範例

每個 cURL、JavaScript 和 Python 範例均會從此契約傳送經驗證的請求,無需特定協定的 SDK。

安裝

Shell
pip install requests
PYTHON
import requests

response = requests.post(
    "https://runapi.ai/v1/responses",
    headers={"Authorization": "Bearer YOUR_API_TOKEN", "Content-Type": "application/json"},
    json={"model": "gpt-5.4", "input": "Summarize one practical improvement for an API deployment.", "moderation": {"model": "omni-moderation-latest", "policy": {"input": {"mode": "score"}, "output": {"mode": "block"}}}}
)
response.raise_for_status()
print(response.json())