Create a response
Creates a response using an OpenAI-compatible request body. Use model ids returned by GET /models.
This endpoint is a text-only subset. Send input as text or supported text messages, and optionally instructions. Read generated text from output[].content[] entries whose type is output_text.
Supported controls are max_output_tokens, temperature, top_p and stream. store must be false. Tools, image/file inputs, structured-output controls, previous_response_id and reasoning controls are not supported. Include history in each request; use Chat Completions when you need its additional controls.
With stream: true, consume named SSE events. Collect delta from response.output_text.delta. The terminal response is in response.completed, response.incomplete or response.failed; inspect its status, usage and error or incomplete details. The stream ends with data: [DONE]. A disconnected stream without a terminal event is not a successful completion.
Python: stream a Responses answer
Use Python 3.9+ and install requests (python -m pip install requests). Set TEXTCORTEX_API_KEY and TEXTCORTEX_MODEL in your environment; choose a model from GET /models. Save and run each example as a separate Python script. These calls use your account's funding. Network/read timeouts raise exceptions; there are no automatic retries. Already printed text is provisional until the completion checks pass. A read timeout is not an overall generation deadline.
import json
import os
import requests
headers = {"Authorization": f"Bearer {os.environ['TEXTCORTEX_API_KEY']}"}
model = os.environ["TEXTCORTEX_MODEL"] # Choose an ID from GET /models.
base = "https://api.textcortex.com/v1"
def events(response):
"""Decode SSE frames, including comments and multiline data."""
response.encoding = "utf-8"
data = []
for line in response.iter_lines(decode_unicode=True):
if line == "":
if data:
yield "\n".join(data)
data = []
elif line.startswith("data:"):
data.append(line[5:].removeprefix(" "))
if data:
raise RuntimeError("Stream ended inside an event")
payload = {"model": model, "input": "Explain an API in one sentence.",
"store": False, "stream": True}
terminal = None
done = False
with requests.post(base + "/responses", headers=headers,
json=payload, stream=True, timeout=(10, 120)) as response:
response.raise_for_status()
for data in events(response):
if data == "[DONE]":
done = True
break
event = json.loads(data)
event_type = event.get("type")
if "error" in event or event_type == "error":
raise RuntimeError(event)
if event_type == "response.output_text.delta":
print(event["delta"], end="", flush=True)
elif event_type in ("response.completed", "response.incomplete", "response.failed"):
terminal = event["response"]
if event_type != "response.completed" or terminal.get("status") != "completed":
raise RuntimeError(terminal.get("error") or terminal.get("incomplete_details") or terminal)
if not done or terminal is None:
raise RuntimeError("Stream disconnected before successful completion")
print("\nUsage:", terminal.get("usage"))
The SSE event name is also present in JSON type. Text arrives in response.output_text.delta; final usage belongs to the terminal response. response.incomplete and response.failed are not successful completion.
Request
- Base URLhttps://api.textcortex.com/v1
- AuthHTTP bearer
Request body
Example request
{
"model": "gpt-6-luna"
}Response
Response object
Changes
No recorded changes to this operation across all 13 revisions of this API.