Przejdź do treści
Dokumentacja API
Dokumentacja API

OpenAI Responses

Wyślij żądanie przez operację Responses kompatybilną z OpenAI w RunAPI.

01

Omówienie

Użyj operacji Responses zgodnej z OpenAI w RunAPI z kompatybilnym modelem oraz kształtami żądań i odpowiedzi protokołu.

Szybki start

  1. Utwórz klucz API i ustaw go jako RUNAPI_API_KEY.
  2. Wybierz zgodny model, a następnie wyślij udokumentowane parametry ścieżki i treść JSON.
  3. Odczytaj odpowiedź JSON lub zdarzenia wysyłane przez serwer pokazane dla tej operacji i obsłuż błędy protokołu.

Punkt końcowy

POST /v1/responses
Bazowy URL
https://runapi.ai
Wersja kontraktu
v1
Preferowane uwierzytelnianie
Authorization: Bearer YOUR_API_TOKEN
02

Nośniki uwierzytelniania

RunAPI akceptuje każdy z wymienionych poniżej protokołów. Wygenerowane przykłady używają preferowanego nagłówka danego protokołu.

header - Preferowane
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

Zgodne modele

Otwórz stronę modelu, aby zapoznać się z aktualnymi cenami, limitami żądań i szczegółami dotyczącymi użytku komercyjnego.

Pokaż 58 kompatybilnych modeli
04

Kontrakt żądania

Treść JSON

Wymieniane są tylko pola mające zarówno publiczną dokumentację protokołu, jak i potwierdzenie obsługi przez RunAPI. Dodatkowe pola treści JSON są przekazywane bez zmian.

Treść JSON13 pola
input["string", "array"]
Opcjonalne

Tekst, elementy wiadomości lub wyniki narzędzi przekazane do modelu.

instructions["string", "null"]
Opcjonalne

Instrukcje systemowe lub deweloperskie dla tej odpowiedzi.

max_output_tokens["integer", "null"]
Opcjonalne

Maksymalna liczba tokenów wyjściowych, wliczając tokeny widoczne i tokeny rozumowania.

modelstring
Wymagane

Identyfikator modelu RunAPI zwrócony przez kompatybilny katalog modeli.

moderation["object", "null"]
Opcjonalne

Zwróć niezależne sygnały moderacji dla bieżącego wejścia i kompletnego wyjścia.

moderation.modelstring
Wymagane Dozwolone wartości: omni-moderation-latest
moderation.policy["object", "null"]
Opcjonalne
moderation.policy.input["object", "null"]
Opcjonalne
moderation.policy.input.modestring
Wymagane Dozwolone wartości: score, block
moderation.policy.output["object", "null"]
Opcjonalne
moderation.policy.output.modestring
Wymagane Dozwolone wartości: score, block
stream["boolean", "null"]
Opcjonalne

Zwróć typowane zdarzenia Responses jako zdarzenia wysyłane przez serwer.

Domyślna wartość: false
toolsarray
Opcjonalne

Narzędzia, które model może wywoływać.

Przykład żądania

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

Odpowiedź synchroniczna

HTTP 200

Schemat

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"
}

Przykład

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

Zdarzenie SSE: output_text_delta

text/event-stream

Schemat

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"
}

Przykład

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

Zdarzenie SSE: completed

text/event-stream

Schemat

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"
}

Przykład

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

Błąd protokołu: invalid_request

HTTP 400

Schemat

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"
}

Przykład

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

Użycie

Schemat

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"
}

Przykład

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

Wygenerowane przykłady kodu

Każdy przykład cURL, JavaScript i Python wysyła zwalidowane żądanie z tej specyfikacji bez konieczności używania SDK właściwego dla protokołu.

Instalacja

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())