Status codes
端点根据请求的成功或失败,在 HTTP 状态行中返回相应的 HTTP 状态码(例如 HTTP/1.1 200 OK 或 HTTP/1.1 400 Bad Request)。常见的状态码包括:
200: 成功400: 请求错误(缺少参数、JSON 无效等)404: 未找到(模型不存在等)429: 请求过多(例如,超过了速率限制)500: 内部服务器错误502: 错误的网关(例如,无法访问云模型时)
Error messages
错误以 application/json 格式返回,结构如下,其中错误消息位于 error 属性中:
json
{
"error": "the model failed to generate a response"
}Errors that occur while streaming
如果在流传输过程中发生错误,该错误将以 application/x-ndjson 格式返回一个对象,其中包含 error 属性。由于响应已经开始,因此不会更改响应的状态码。
json
{"model":"gemma4","created_at":"2025-10-26T17:21:21.196249Z","response":" Yes","done":false}
{"model":"gemma4","created_at":"2025-10-26T17:21:21.207235Z","response":".","done":false}
{"model":"gemma4","created_at":"2025-10-26T17:21:21.219166Z","response":"I","done":false}
{"model":"gemma4","created_at":"2025-10-26T17:21:21.231094Z","response":"can","done":false}
{"error":"an error was encountered while running the model"}