This guide has an independently written Vietnamese edition. Đọc bằng Tiếng Việt
Create a response
POST /v1/responses accepts a text input and a routing model. In the default strict idempotency policy, include an Idempotency-Key for the create request. store defaults to true.
import os
from uuid import uuid4
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TASKWAY_API_KEY"],
base_url=os.environ["TASKWAY_BASE_URL"],
)
first = client.responses.create(
model="auto",
input="Explain an AI gateway in one sentence.",
extra_headers={"Idempotency-Key": str(uuid4())},
)
print(first.output_text)
follow_up = client.responses.create(
model="auto",
previous_response_id=first.id,
input="Now give me a three-step example.",
extra_headers={"Idempotency-Key": str(uuid4())},
)
print(follow_up.output_text)
import { randomUUID } from "node:crypto";
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.TASKWAY_API_KEY,
baseURL: process.env.TASKWAY_BASE_URL,
});
const first = await client.responses.create(
{ model: "auto", input: "Explain an AI gateway in one sentence." },
{ headers: { "Idempotency-Key": randomUUID() } },
);
console.log(first.output_text);
const followUp = await client.responses.create(
{
model: "auto",
previous_response_id: first.id,
input: "Now give me a three-step example.",
},
{ headers: { "Idempotency-Key": randomUUID() } },
);
console.log(followUp.output_text);
Use a concrete visible model for embeddings; the text-generation routing aliases apply to Responses and Chat, not Embeddings.
Continue a response
When store is true, the response is kept for up to 30 days. Pass its id as previous_response_id to continue the same application’s history. Give every create request a new idempotency key. The previous response must still exist, be unexpired, and belong to the same application key’s application.
Send new instructions on each request when needed. A new instructions value replaces the previous one; instructions are not inherited. Resolved history is limited to 200 messages. Deleting or expiring a response clears its public content and history. With store=false, the response is not publicly retrievable and cannot be used as previous_response_id.
Manage stored responses
- Retrieve:
GET /v1/responses/{response_id}. - Delete:
DELETE /v1/responses/{response_id}. - Stored responses and their history are scoped to one application. A response from another application’s key is not visible.
Supported options
The validated profile supports text and message input, instructions, store, stream, previous_response_id, max_output_tokens, supported sampling settings, function tools, and text output formats. background=true, reasoning, conversation, include, text.verbosity, max_tool_calls and automatic truncation are not supported. Unknown request fields are rejected by the strict Responses request schema.
For a complete feature matrix, see compatibility. For streaming behavior and tool hand-offs, see function tools and streaming.