Responses (بتا)
POST /v1/responses نسخهٔ سازگار با Responses API OpenAI است: با client.responses.create(...) در SDKهای رسمی کار میکند. این اندپوینت در وضعیت بتاست. نسخهٔ SDK خود را پین کنید. ورودی صدا در این اندپوینت پشتیبانی نمیشود و باید از چت استفاده کنید.
/v1/responsesاحراز هویت Bearer[BETA] Create a response (OpenAI Responses API compatible)
⚠ Beta. This endpoint is in public beta. The request/response shape may change without notice. Pin your SDK version and add a contract test before shipping production traffic.
Generate a model response in the OpenAI Responses API shape. Drop-in
compatible with openai-python (>= 1.50) and openai-node (>= 4.50)
via client.responses.create(...).
Two modes:
- Non-streaming (default): returns the full Response object as JSON.
- Streaming (
"stream": true): returns Server-Sent Events. Named events:response.created,response.output_item.added,response.content_part.added,response.content_part.delta(text chunk delta),response.output_item.done, and the terminal frameresponse.doneorresponse.completedcarrying the final usage block. Stream terminates withdata: [DONE].
Function tools (type: "function") are supported and forwarded
verbatim. Built-in tools (web_search, file_search,
code_interpreter, computer_use, mcp, image_generation)
return 400 UNSUPPORTED_TOOL in beta.
Images: pass {"type":"input_image","image_url":"https://..."}
inside an input message item. The image_url may be a fully
qualified URL or a data: URI. Iran-hosted images are auto-proxied
through the gateway so foreign-IP upstreams can read them.
Multi-turn: previous_response_id works only on models whose
apis list in GET /v1/models includes responses, and only with
the id of an earlier response from your own account on such a model.
Otherwise the request is refused before anything is charged:
400 MULTI_TURN_NOT_SUPPORTED (model keeps no state) or
400 PREVIOUS_RESPONSE_NOT_FOUND (not one of your stored responses).
conversation is not supported (400 CONVERSATION_NOT_SUPPORTED).
Resend the earlier turns in input, or use POST /v1/chat/completions.
Billing: a hold is placed based on estimated tokens, then
settled inline from usage on the response. No client action
needed. Same hold/settle pipeline as /v1/chat/completions.
پارامترها
| فیلد | in | نوع | توضیح |
|---|---|---|---|
Idempotency-Key | header | string | Optional deduplication token (any string up to 200 characters). How it works:
When to use: Add this header when you want to safely retry a request after a network timeout without risking a duplicate operation. |
بدنه درخواستالزامی
| فیلد | نوع | توضیح |
|---|---|---|
modelالزامی | string | نمونه: |
inputالزامی | string | array of object | Plain string OR array of input items. |
instructions | string | |
max_output_tokens | integer | |
temperature | number | |
top_p | number | |
stream | boolean | پیشفرض: |
store | boolean | Forwarded upstream; no server-side persistence on Hormouz. |
previous_response_id | string | |
tools | array of object | Same tool flavours as |
tool_choice | string | object | |
metadata | object | |
parallel_tool_calls | boolean | |
reasoning | object | |
text | object |
نمونه
پاسخها
200هدرها: X-Hormouz-Admission-Latency-Ms, X-Hormouz-Upstream-Latency-Ms, X-Hormouz-Proxy-Latency-MsSuccess. JSON object, or SSE stream when stream:true.
400Bad request. Codes:
BAD_REQUEST: malformed JSON or missing required fields.INVALID_TOOLS::onlinemodel suffix,plugins:[{id:"web"}], or an internal<internal>:*tool-type prefix in the request body.UNSUPPORTED_TOOL: built-in tool whose pricing is not yet wired (file_search,code_interpreter,computer_use,mcp).
401Authentication failed. Either the Authorization header is missing,
the key format is invalid, or the key doesn't match any active account.
{
"error": {
"code": "UNAUTHORIZED",
"message": "Authentication required",
"status": 401
}
}402Insufficient credits.
409Idempotency key conflict: you sent the same Idempotency-Key with
a different request body.
413Request body too large after image inlining (> 25 MiB).
429Too many requests. Back off and retry after a short delay.
Check the Retry-After header for guidance.
499Your HTTP client cancelled the request before the gateway finished. No charge: the hold has been released. The most common cause is a 30 s default client timeout against a model whose p95 latency is 45-60 s; bump your client timeout to 120 s.
Retries with the same Idempotency-Key will replay this 499
forever (the prior outcome is "you cancelled"). For an actual
re-attempt, mint a fresh Idempotency-Key. See
docs/CUSTOMER_ERROR_HANDLING.md §3 for the full contract.
{
"error": {
"code": "CLIENT_CLOSED",
"message": "Client disconnected before response",
"status": 499
}
}500Unexpected server error. Please retry with exponential backoff. If the issue persists, contact your admin.
502Bad Gateway. Upstream returned a 5xx after all retries were exhausted, OR upstream sent an unexpected redirect on the streaming path (Hormouz synthesises a 502 rather than forward an HTML/Location body as SSE).
503Service Unavailable. The proxy could not reach the upstream provider (network failure, classifier unavailable). Retry with a fresh Idempotency-Key.
504The gateway's 120 s upstream deadline elapsed before the upstream
provider produced a response. Retry with the same
Idempotency-Key so a delayed-but-eventually-successful upstream
call can be replayed instead of re-charged. Consider switching
to a faster model or capping max_tokens if this recurs.
{
"error": {
"code": "UPSTREAM_TIMEOUT",
"message": "Upstream did not respond before timeout",
"status": 504
}
}