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 input parameter accepts strings or message arrays
  • output_text shortcut 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

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

User

The human's messages — questions, instructions, or content for the model to process. This is where your application passes input.

assistant

Assistant

The model's previous responses. Include these to give the model memory of what it has already said in a conversation.

python
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)
javascript
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.

python
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)
Server-side storage: GlomaxGPT stores conversation history on its servers. Responses are retained for 30 days by default. This approach minimizes data you need to manage but incurs storage costs.
python
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?"))
Client-side storage: You manage the history. This gives you full control — truncate, summarize, or filter messages as needed. Useful when you need to store conversations in your own database.

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.

python
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}")
javascript
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.

python
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")
javascript
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);
python
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.

Rule of thumb: 1 token ≈ 4 characters or ¾ of a word in English. "GlomaxGPT is great!" is about 6 tokens. Code and non-English text may tokenize differently.
python
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-mini for simple tasks
  • Set max_output_tokens to 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.

1

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."

2

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.

3

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.

python
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
4

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.

5

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.

python
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"""