GetAPI.ONE
Stream Responses from GetAPI.ONE
Consume a server-sent event stream, append only text deltas, and treat completed, failed, and incomplete events as distinct terminal outcomes.
Choose a compatible path
- Use a current catalog model whose declared endpoint is Responses.
- Keep the API key in a trusted server or local process.
- Decide how the caller will display partial text and recover from an interrupted stream.
POST https://www.getapi.one/v1/responses
Accept: text/event-stream
Authorization: Bearer $GETAPI_ONE_API_KEYRead the event lifecycle
- Send stream=true through a server-side SDK or HTTP client with automatic retries disabled for the first controlled request.
- Append only response.output_text.delta payloads to visible text.
- Stop on response.completed and keep the final response metadata needed by your application.
- Surface response.failed and response.incomplete as non-success outcomes; do not label partial text complete.
- Treat an error event, transport exception, EOF before completion, or local cancellation as non-success and close the stream.
import os
from openai import OpenAI
terminal_event = None
try:
with OpenAI(
api_key=os.environ["GETAPI_ONE_API_KEY"],
base_url="https://www.getapi.one/v1",
timeout=30.0,
max_retries=0,
) as client:
with client.responses.create(
model="<RESPONSES_MODEL_ID_FROM_CURRENT_CATALOG>",
input="Give three concise deployment checks.",
stream=True,
) as stream:
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
elif event.type == "response.completed":
terminal_event = event.type
print("\ncompleted")
break
elif event.type in {"response.failed", "response.incomplete", "error"}:
terminal_event = event.type
raise RuntimeError(f"stream ended with {event.type}: {event}")
except KeyboardInterrupt:
raise SystemExit("cancelled locally; the stream and client were closed")
if terminal_event != "response.completed":
raise RuntimeError("stream ended before response.completed")Map events to UI state
| Event | Application action |
|---|---|
| response.output_text.delta | Append event.delta; do not replace previously rendered text. |
| response.completed | Mark success and close loading state. |
| response.failed | Show the structured error and a safe retry action. |
| response.incomplete | Keep partial output visibly incomplete and inspect incomplete details. |
Verify the expected result
- Text appears incrementally without duplicated deltas.
- Loading ends only after a terminal event or transport error.
- An interrupted connection never displays a false success state.
Handle transport and protocol errors
- If no events arrive, verify the exact /v1/responses route, stream=true, proxy buffering, and the model endpoint declaration.
- If output repeats, append each delta once and do not combine SDK accumulated output with raw events.
- Retry only before visible side effects or with application-level idempotency; a disconnect does not prove the upstream request did nothing.
Keep streaming server-side
Browser → your authenticated backend → GetAPI.ONE
server-held key only