What changes from Chat Completions
Responses sends input to /v1/responses. A raw result contains output items and a response status; it is not a choices array. Output may include reasoning items, messages or function calls, so output[0] must not be assumed to be user-facing text.
The OpenAI Python SDK exposes output_text as a convenience for text messages. That convenience does not execute a function call or validate an application-specific JSON schema. Keep those responsibilities in your application.
One complete text request
Install the openai Python package. Set CLODEX_API_KEY in protected server-side configuration and select a Responses-capable model in CLODEX_MODEL. The example makes one billable request and disables SDK retries so a failure is not hidden behind additional calls.
It requires completed status and nonempty text. This is a deliberate text-only contract; an application expecting tool calls must branch on output item type instead of treating an empty output_text as a generic failure.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["CLODEX_API_KEY"],
base_url="https://clodex.xyz/v1",
timeout=60.0,
max_retries=0,
)
response = client.responses.create(
model=os.environ["CLODEX_MODEL"],
input="Reply with one word: ready",
stream=False,
)
if response.status != "completed" or not response.output_text.strip():
raise RuntimeError(f"Incomplete text response: {response.status}")
print(response.output_text)
print(response.usage)
Function calls need an application loop
A function-call item describes a requested operation. Your backend checks the function name, validates arguments and verifies the user’s authorization before executing it. A model-generated call is not permission to charge money, delete files or access another user’s data.
Return the tool result with the call identifier required by the Responses contract, then let the model continue. Give side-effecting operations their own deduplication key. Replaying a model request after a network error must not replay a payment.
Streaming: wait for the terminal event
An HTTP 200 can arrive before the model finishes. Accumulate text deltas for display, but commit the final answer only after a completed response. Incomplete and failed events belong to separate paths. End-of-file without a terminal event is an interrupted stream, not an empty successful response.
A client timeout does not establish whether processing stopped upstream. Retain the safe request or task identifier and check usage before resubmitting. Do not hide interruption by concatenating a new generation onto the old partial text.
Conversation state and hosted tools
OpenAI’s direct API documents stateful continuation and hosted tools. A compatible gateway may expose a smaller subset. Do not assume previous_response_id, server-side storage, web search, file search or computer use are supported merely because /v1/responses accepts a text request.
If you implement explicit history, preserve complete items and the relation between tool calls and results. Limit history deliberately and keep system instructions separate from retrieved documents. For Codex, use the supported provider configuration rather than manually rebuilding its event loop.
CLODEx integration documentation · Codex configuration · OpenAI: Responses migration
Documentation and example scope
Connection settings follow CLODEx documentation. Examples target the stated protocol; they are not recorded inference results and do not promise identical features across models. A successful generation request can incur a charge.
Frequently asked questions
Why not read output[0]?
The first item can be reasoning or a function call. Inspect item types or use the SDK text helper for a text-only request.
Does output_text prove a tool ran?
No. Tool execution happens in your backend or an explicitly configured hosted tool. Track the call and its result separately.
Can I reuse every direct OpenAI feature?
Not automatically. Verify the exact gateway route and feature. Protocol compatibility is not a claim of identical storage, tools or account policy.