Metin Üretimi
Learn how to generate text using the Responses API. Understand message roles, conversation management, streaming, JSON mode, and prompt engineering best practices.
The Responses API
The Responses API is GlomaxGPT's primary interface for text generation. It supports single-turn and multi-turn conversations, built-in tools, structured outputs, and streaming. It is designed to be simple for common cases while offering full control for advanced use.
Key Features
- Single
inputparameter accepts strings or message arrays output_textshortcut for text responses- Built-in web search and file search tools
- Conversation continuity via
previous_response_id - Streaming with Server-Sent Events
- Structured JSON output with schema enforcement
Supported Models
- glomaxgpt-pro — Most capable, best instruction following
- glomaxgpt-mini — Fast and cost-efficient
- glomaxgpt-pro-nano — Lowest latency, lowest cost
- glomaxgpt-think — Deep reasoning tasks
- glomaxgpt-think-mini — Efficient reasoning
- glomaxgpt-standard — Multimodal, previous generation
Messages & Roles
Conversations are built from messages, each with a role that tells the model who is speaking. There are three primary roles.
System
Sets the overall behavior, persona, and constraints of the model. Think of it as the model's job description. Applied at the start of every conversation.
User
The human's messages — questions, instructions, or content for the model to process. This is where your application passes input.
Assistant
The model's previous responses. Include these to give the model memory of what it has already said in a conversation.
from GlomaxGPT import GlomaxGPT
client = GlomaxGPT()
response = client.responses.create(
model="glomaxgpt-pro",
instructions="""You are an expert Python tutor.
Explain concepts clearly with practical examples.
When showing code, always include comments.
Keep explanations beginner-friendly.""",
input=[
{
"role": "user",
"content": "What is a Python decorator?"
},
{
"role": "assistant",
"content": "A decorator is a function that wraps another function to add behavior..."
},
{
"role": "user",
"content": "Can you show me a real-world example using @property?"
}
]
)
print(response.output_text)
import GlomaxGPT from "GlomaxGPT";
const client = new GlomaxGPT();
const response = await client.responses.create({
model: "glomaxgpt-pro",
instructions: `You are an expert Python tutor.
Explain concepts clearly with practical examples.
When showing code, always include comments.`,
input: [
{ role: "user", content: "What is a Python decorator?" },
{ role: "assistant", content: "A decorator is a function that wraps another function..." },
{ role: "user", content: "Can you show me a real-world example using @property?" },
],
});
console.log(response.output_text);
Conversation State
There are two ways to maintain conversation history: using previous_response_id for server-side storage, or passing the full message history yourself.
from GlomaxGPT import GlomaxGPT
client = GlomaxGPT()
# Turn 1
r1 = client.responses.create(
model="glomaxgpt-pro",
instructions="You are a helpful travel advisor.",
input="I want to visit Japan in spring. What cities should I see?"
)
print(r1.output_text)
# Turn 2 — model remembers turn 1
r2 = client.responses.create(
model="glomaxgpt-pro",
previous_response_id=r1.id,
input="How many days should I spend in each?"
)
print(r2.output_text)
# Turn 3 — model remembers turns 1 and 2
r3 = client.responses.create(
model="glomaxgpt-pro",
previous_response_id=r2.id,
input="What are the best cherry blossom spots?"
)
print(r3.output_text)
from GlomaxGPT import GlomaxGPT
client = GlomaxGPT()
# Maintain history in your application
history = []
def chat(user_message: str) -> str:
history.append({"role": "user", "content": user_message})
response = client.responses.create(
model="glomaxgpt-pro",
instructions="You are a helpful travel advisor.",
input=history
)
assistant_message = response.output_text
history.append({"role": "assistant", "content": assistant_message})
return assistant_message
print(chat("I want to visit Japan in spring. What cities should I see?"))
print(chat("How many days should I spend in each?"))
print(chat("What are the best cherry blossom spots?"))
Akış
Streaming delivers tokens to the user as they are generated, greatly improving perceived responsiveness for longer outputs. Use the .stream() helper for the best experience.
from GlomaxGPT import GlomaxGPT
client = GlomaxGPT()
# High-level streaming helper
with client.responses.stream(
model="glomaxgpt-pro",
instructions="You are a creative writer.",
input="Write a 3-paragraph short story about an astronaut who discovers music on Mars."
) as stream:
for text in stream.text_deltas:
print(text, end="", flush=True)
# After streaming, get the complete response
final = stream.get_final_response()
print(f"\n\nTokens used: {final.usage.total_tokens}")
# Low-level event stream
stream = client.responses.create(
model="glomaxgpt-pro",
input="Explain how neural networks learn.",
stream=True
)
for event in stream:
match event.type:
case "response.text.delta":
print(event.delta, end="", flush=True)
case "response.completed":
print(f"\nDone. Input: {event.response.usage.input_tokens}, Output: {event.response.usage.output_tokens}")
import GlomaxGPT from "GlomaxGPT";
const client = new GlomaxGPT();
// High-level streaming
const stream = await client.responses.stream({
model: "glomaxgpt-pro",
instructions: "You are a creative writer.",
input: "Write a short story about an astronaut who discovers music on Mars.",
});
for await (const chunk of stream) {
if (chunk.type === "response.text.delta") {
process.stdout.write(chunk.delta);
}
}
// Get final response metadata
const finalResponse = await stream.finalResponse();
console.log(`\nTotal tokens: ${finalResponse.usage.total_tokens}`);
// Pipe to HTTP response (Express example)
app.post("/chat", async (req, res) => {
res.setHeader("Content-Type", "text/event-stream");
const stream = await client.responses.stream({ model: "glomaxgpt-pro", input: req.body.message });
for await (const chunk of stream) {
if (chunk.type === "response.text.delta") res.write(`data: ${chunk.delta}\n\n`);
}
res.end();
});
Structured JSON Output
Force the model to return valid JSON matching a schema you define. This is ideal for extracting structured data, building APIs, or any use case where you need machine-readable output.
from GlomaxGPT import GlomaxGPT
from pydantic import BaseModel
client = GlomaxGPT()
class CalendarEvent(BaseModel):
title: str
date: str
location: str
attendees: list[str]
description: str
duration_minutes: int
response = client.responses.parse(
model="glomaxgpt-pro",
input="Extract event details: Team sync meeting on Friday Dec 20th at 2pm in Conference Room B. Sarah, John, and Maya will attend. It's a 45-minute quarterly review.",
text_format=CalendarEvent
)
event = response.output_parsed
print(f"Title: {event.title}")
print(f"Date: {event.date}")
print(f"Attendees: {', '.join(event.attendees)}")
print(f"Duration: {event.duration_minutes} minutes")
import GlomaxGPT from "GlomaxGPT";
import { z } from "zod";
import { zodResponseFormat } from "GlomaxGPT/helpers/zod";
const client = new GlomaxGPT();
const CalendarEvent = z.object({
title: z.string(),
date: z.string(),
location: z.string(),
attendees: z.array(z.string()),
description: z.string(),
duration_minutes: z.number(),
});
const response = await client.responses.parse({
model: "glomaxgpt-pro",
input: "Extract event details: Team sync on Friday Dec 20th at 2pm...",
text_format: zodResponseFormat(CalendarEvent, "calendar_event"),
});
const event = response.output_parsed;
console.log(event.title, event.attendees);
from GlomaxGPT import GlomaxGPT
client = GlomaxGPT()
schema = {
"type": "object",
"properties": {
"title": {"type": "string"},
"date": {"type": "string", "format": "date"},
"attendees": {"type": "array", "items": {"type": "string"}},
"duration_minutes": {"type": "integer"}
},
"required": ["title", "date", "attendees", "duration_minutes"],
"additionalProperties": False
}
response = client.responses.create(
model="glomaxgpt-pro",
input="Extract event: Team sync Friday Dec 20th 2pm, Sarah and John, 45 minutes.",
text={
"format": {
"type": "json_schema",
"name": "calendar_event",
"schema": schema,
"strict": True
}
}
)
import json
event = json.loads(response.output_text)
print(event)
Token Management
Tokens are the basic unit of text for language models. Understanding token usage helps you optimize cost and stay within context limits.
from GlomaxGPT import GlomaxGPT
client = GlomaxGPT()
response = client.responses.create(
model="glomaxgpt-pro",
input="Summarize the history of the internet in 3 sentences.",
max_output_tokens=200 # Limit output length
)
# Inspect token usage
print(f"Input tokens: {response.usage.input_tokens}")
print(f"Output tokens: {response.usage.output_tokens}")
print(f"Total tokens: {response.usage.total_tokens}")
print(f"Cached tokens: {response.usage.input_tokens_details.cached_tokens}")
# Count tokens before making a request
import tiktoken
enc = tiktoken.encoding_for_model("glomaxgpt-pro")
tokens = enc.encode("Your text here")
print(f"Token count: {len(tokens)}")
Context Windows
- glomaxgpt-pro — 1,047,576 tokens (~800K words)
- glomaxgpt-mini — 1,047,576 tokens
- glomaxgpt-pro-nano — 1,047,576 tokens
- glomaxgpt-think — 200,000 tokens
- glomaxgpt-think-mini — 200,000 tokens
Cost Optimization
- Use prompt caching for repeated system prompts
- Use
glomaxgpt-minifor simple tasks - Set
max_output_tokensto avoid runaway outputs - Batch requests with the Batch API for 50% discount
Prompt Engineering Tips
Well-crafted prompts are the most effective lever for improving model output quality. These principles apply across all models.
Be specific and explicit
State exactly what you want, including format, length, tone, and any constraints. Vague prompts produce vague outputs. Instead of "write about dogs," say "Write a 3-paragraph article for first-time dog owners explaining the top 3 breeds for apartments, using a friendly, encouraging tone."
Use positive framing
Tell the model what to do, not what to avoid. "Respond only in English" works better than "Don't respond in other languages." Positive instructions are less likely to be missed or misinterpreted.
Provide examples (few-shot)
Show the model examples of ideal input-output pairs in your prompt. Even 2-3 examples dramatically improve consistency for formatting, classification, and extraction tasks.
instructions = """Classify customer sentiment. Reply with only: positive, negative, or neutral.
Examples:
Input: "Your product saved my day!" → positive
Input: "Took forever to arrive." → negative
Input: "Package arrived on time." → neutral"""
response = client.responses.create(
model="glomaxgpt-pro",
instructions=instructions,
input="The chatbot was somewhat helpful but confusing at times."
)
print(response.output_text) # neutral
Ask for step-by-step reasoning
For complex tasks, add "Think step by step" or "Reason through this carefully before answering." This engages the model's chain-of-thought capabilities and reduces errors on logic and math problems. For best results with reasoning tasks, consider using the glomaxgpt-think or glomaxgpt-think-mini models.
Use delimiters for structure
Use XML tags, triple backticks, or clear headers to separate different parts of your prompt — especially when mixing instructions with user-provided content.
user_document = "..." # potentially long user content
prompt = f"""Summarize the following document in 3 bullet points.
<document>
{user_document}
</document>
Requirements:
- Each bullet point should be one sentence
- Focus on the main conclusions
- Use plain language"""