Skip to main content
Back to Responses API Guide
Cookbook

Responses API Cookbook

Copy, paste, run. Start with recipe 1, add what you need.

1

Ask a question

When to use

You need a quick answer. One message, one response.

Python
from openai import OpenAI

client = OpenAI(
base_url="https://accomplishanything.today/api/v1/cadreen",
api_key="sk_cadreen_..."
)

response = client.responses.create(
model="cadreen",
input="What's the weather in Lagos?"
)
print(response.output_text)
TypeScript
import OpenAI from "openai";

const client = new OpenAI({
baseURL: "https://accomplishanything.today/api/v1/cadreen",
apiKey: "sk_cadreen_...",
});

const response = await client.responses.create({
model: "cadreen",
input: "What's the weather in Lagos?",
});
console.log(response.output_text);
curl
curl -X POST https://accomplishanything.today/api/v1/cadreen/responses \
-H "Authorization: Bearer sk_cadreen_..." \
-H "Content-Type: application/json" \
-d '{
"model": "cadreen",
"input": "What is the weather in Lagos?"
}'
Note
instructions vs input: Use instructions for system-level guidance that persists across turns. Use input for the user's message.
2

Have a conversation

When to use

Each turn builds on the last. You want the AI to remember what it just said.

Python
# Turn 1
res1 = client.responses.create(
model="cadreen",
input="What is the capital of France?",
instructions="You are a geography expert.",
store=True
)
print(res1.output_text) # "The capital of France is Paris."

# Turn 2 — Cadreen remembers the context
res2 = client.responses.create(
model="cadreen",
input="And its population?",
instructions="You are a geography expert.",
previous_response_id=res1.id,
store=True
)
print(res2.output_text) # "Paris has approximately 2.1 million people..."
Note
Resend instructions on each request. System guidance doesn't carry over automatically — send it again with each turn.
3

Let it use your tools

When to use

You need the AI to do something in the real world — read files, query databases, call APIs. Cadreen checks your rules before calling any tool.

Python
response = client.responses.create(
model="cadreen",
input="Read main.go and tell me what it does",
tools=[{
"type": "function",
"function": {
"name": "read_file",
"description": "Read the contents of a file",
"parameters": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Absolute file path"
}
},
"required": ["path"]
}
}
}]
)

# Cadreen returns a tool call — you execute it
for item in response.output:
if item.type == "function_call":
print(f"Tool: {item.name}")
print(f"Arguments: {item.arguments}")
# Execute the tool and send the result back
Note
Cadreen doesn't execute your tools — it tells you which tool to call and with what arguments. You run it and send the result back. Cadreen's own tools (memory, learning) run automatically.
4

Stream text in real time

When to use

You're building a chat UI or handling long responses. Show text as it arrives instead of making the user wait.

Python
stream = client.responses.create(
model="cadreen",
input="Explain quantum computing in simple terms",
stream=True
)

for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
elif event.type == "response.completed":
print("\n\n[Done]")
TypeScript
const stream = await client.responses.create({
model: "cadreen",
input: "Explain quantum computing in simple terms",
stream: true,
});

for await (const event of stream) {
if (event.type === "response.output_text.delta") {
process.stdout.write(event.delta);
}
}
5

Get structured JSON

When to use

You need the response as data, not text. For APIs, data pipelines, or anything that parses JSON.

Python
response = client.responses.create(
model="cadreen",
input="What are the top 3 issues in my project?",
text={
"format": {
"type": "json_schema",
"name": "issues",
"schema": {
"type": "object",
"properties": {
"issues": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {"type": "string"},
"severity": {"type": "string", "enum": ["low", "medium", "high"]},
"description": {"type": "string"}
},
"required": ["title", "severity", "description"]
}
}
},
"required": ["issues"]
}
}
}
)

import json
issues = json.loads(response.output_text)
Note
Heads up: Structured output is defined but not yet enforced. Parse the output defensively — it may not always match the schema exactly.
6

Put it all together

Most real apps combine patterns. Here's streaming + tools + conversation in one request:

Python
stream = client.responses.create(
model="cadreen",
input="Read my config and tell me what's wrong",
instructions="You are a senior DevOps engineer.",
tools=[{
"type": "function",
"function": {
"name": "read_file",
"description": "Read a file",
"parameters": {
"type": "object",
"properties": {
"path": {"type": "string"}
},
"required": ["path"]
}
}
}],
stream=True,
store=True
)

for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
elif event.type == "response.function_call_arguments.done":
print(f"\nCalling: {event.name}({event.arguments})")
Note
Start simple, add what you need. Most apps only need recipes 1 and 4. Add tools and structured output when your use case demands it.
Note
See also: Responses API Guide — the full reference for all fields and behavior.