Zum Inhalt springen
API-Referenz
API-Referenz

OpenAI Responses

Eine Anfrage über RunAPIs OpenAI-kompatible Responses-Operation senden.

01

Übersicht

Verwende RunAPI's OpenAI-kompatible Responses-Operation mit einem kompatiblen Modell sowie den Anfrage- und Antwortstrukturen des Protokolls.

Schnellstart

  1. Erstellen Sie einen API-Schlüssel und setzen Sie ihn als RUNAPI_API_KEY.
  2. Wählen Sie ein kompatibles Modell, senden Sie dann die dokumentierten Pfadparameter und den JSON-Body.
  3. Lesen Sie die für diesen Vorgang angezeigte JSON-Antwort oder die server-sent events und behandeln Sie Protokollfehler.

Endpunkt

POST /v1/responses
Basis-URL
https://runapi.ai
Vertragsversion
v1
Bevorzugte Authentifizierung
Authorization: Bearer YOUR_API_TOKEN
02

Authentifizierungsträger

RunAPI akzeptiert jeden der unten aufgeführten Träger. Generierte Beispiele verwenden den bevorzugten Header des Protokolls.

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

Kompatible Modelle

Öffnen Sie eine Modellseite für aktuelle Preise, Ratenlimits und Details zur kommerziellen Nutzung.

58 kompatible Modelle anzeigen
04

Anfrage-Vertrag

JSON-Body

Es werden nur Felder aufgeführt, für die sowohl öffentliche Protokoll- als auch RunAPI-Unterstützung belegt ist. Weitere JSON-Body-Felder werden durchgereicht.

JSON-Body13 Felder
input["string", "array"]
Optional

Text, Nachrichtenelemente oder Tool-Ergebnisse, die dem Modell bereitgestellt werden.

instructions["string", "null"]
Optional

System- oder Entwickleranweisungen für diese Antwort.

max_output_tokens["integer", "null"]
Optional

Maximale Anzahl von Ausgabe-Tokens, einschließlich sichtbarer und Reasoning-Tokens.

modelstring
Erforderlich

RunAPI-Modellbezeichner, der vom kompatiblen Modellkatalog zurückgegeben wird.

moderation["object", "null"]
Optional

Unabhängige Moderationssignale für die aktuelle Eingabe und die vollständige Ausgabe zurückgeben.

moderation.modelstring
Erforderlich Zulässige Werte: omni-moderation-latest
moderation.policy["object", "null"]
Optional
moderation.policy.input["object", "null"]
Optional
moderation.policy.input.modestring
Erforderlich Zulässige Werte: score, block
moderation.policy.output["object", "null"]
Optional
moderation.policy.output.modestring
Erforderlich Zulässige Werte: score, block
stream["boolean", "null"]
Optional

Typisierte Responses-Ereignisse als Server-Sent Events zurückgeben.

Standard: false
toolsarray
Optional

Tools, die das Modell aufrufen darf.

Anfragebeispiel

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

Synchrone Antwort

HTTP 200

Schema

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

Beispiel

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 event: output_text_delta

text/event-stream

Schema

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

Beispiel

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

SSE-Ereignis: Abgeschlossen

text/event-stream

Schema

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

Beispiel

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

Protokollfehler: invalid_request

HTTP 400

Schema

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

Beispiel

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

Verwendung

Schema

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

Beispiel

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

Generierte Code-Beispiele

Jedes cURL-, JavaScript- und Python-Beispiel sendet die validierte Anfrage aus diesem Vertrag, ohne ein protokollspezifisches SDK zu benötigen.

Installieren

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