
The GPT-6.2 API is OpenAI's current pick for agent work: the API changelog recommends gpt-6.2-sol "for everyday coding and agent workflows" and gpt-6.2-astra for "demanding reasoning and coding tasks." This guide wires either model into a coding agent through PoYo's Responses endpoint, with function tools, a bounded loop, streamed progress, a large repository context, and caching that keeps long sessions affordable. Start on the GPT-6.2 Sol model page and keep GPT-6.2 Astra for escalation.
If you haven't sent a first request yet, start with the GPT-6.2 API guide.
What the API gives a coding agent
| Item | GPT-6.2 on PoYo |
|---|---|
| Model IDs | gpt-6.2-sol (default), gpt-6.2-astra (escalation) |
| Agent endpoint | POST https://api.poyo.ai/v1/responses (OpenAI SDK, base_url="https://api.poyo.ai/v1") |
| Tool calling | Responses only; OpenAI: "tool calling requires Responses" |
| Context / max input / max output | 1,050,000 / 922,000 / 128,000 tokens |
| Streaming | "stream": true; response.completed carries the final output and usage |
| Reasoning | reasoning.effort; none rejected, start at medium |
| Price per 1M (Sol) | $1.60 input / $8 output / $0.08 cache read / $2 cache write |
| Price per 1M (Astra) | $6.40 input / $32 output / $0.32 cache read / $8 cache write |
| Errors | 400 invalid fields, 401 bad key, 402 insufficient credits, 404 unknown model; retry 429 / 5xx with backoff |
PoYo's Responses reference documents tools, tool_choice, parallel_tool_calls, reasoning, include, store, previous_response_id, and truncation, and says tool support depends on the model. OpenAI's model pages list function calling and a set of hosted tools for GPT-6.2. PoYo's docs show only web_search_preview as a hosted-tool example, so this agent uses your own function tools, which you control end to end.
Define function tools
Keep the tool set small and safe. The model can only request actions you implement:
import json, os, subprocess
from pathlib import Path
from openai import OpenAI
client = OpenAI(base_url="https://api.poyo.ai/v1", api_key=os.environ["POYO_API_KEY"])
REPO = Path("/srv/checkout").resolve()
TOOLS = [
{"type": "function", "name": "read_file",
"description": "Read a UTF-8 text file from the repository.",
"parameters": {"type": "object", "properties": {"path": {"type": "string"}},
"required": ["path"], "additionalProperties": False}},
{"type": "function", "name": "write_file",
"description": "Replace a file in the repository with new content.",
"parameters": {"type": "object",
"properties": {"path": {"type": "string"}, "content": {"type": "string"}},
"required": ["path", "content"], "additionalProperties": False}},
{"type": "function", "name": "run_tests",
"description": "Run the test suite and return the last 200 lines of output.",
"parameters": {"type": "object", "properties": {}, "additionalProperties": False}},
]
def safe_path(p: str) -> Path:
full = (REPO / p).resolve()
if not full.is_relative_to(REPO):
raise ValueError("path escapes the repository")
return full
def call_tool(name: str, args: dict) -> str:
try:
if name == "read_file":
return safe_path(args["path"]).read_text(encoding="utf-8")[:200_000]
if name == "write_file":
safe_path(args["path"]).write_text(args["content"], encoding="utf-8")
return "ok"
if name == "run_tests":
r = subprocess.run(["pytest", "-q"], cwd=REPO, capture_output=True, text=True, timeout=600)
return "\n".join((r.stdout + r.stderr).splitlines()[-200:])
return f"unknown tool {name}"
except Exception as e: # return errors to the model instead of crashing the loop
return f"error: {e}"
Run the agent against a disposable checkout or container, never your working tree.
A bounded agent loop
The loop sends the conversation, executes every function_call item, appends a function_call_output with the same call_id, and repeats until the model answers without a tool call. It stops at a turn limit and a dollar budget.
PRICES = {"gpt-6.2-sol": (1.60, 8.00, 0.08, 2.00), "gpt-6.2-astra": (6.40, 32.00, 0.32, 8.00)}
def cost(model, u) -> float:
p_in, p_out, p_read, p_write = PRICES[model]
d = getattr(u, "input_tokens_details", None)
read = getattr(d, "cached_tokens", 0) or 0
write = getattr(d, "cache_write_tokens", 0) or 0
return ((u.input_tokens - read - write) * p_in + read * p_read
+ write * p_write + u.output_tokens * p_out) / 1e6
DEVELOPER = ("You are a coding agent working in a Python repository. "
"Read files before editing. Run the tests after every change. "
"When the tests pass, reply with a short summary and no tool call.")
def run_agent(task: str, model="gpt-6.2-sol", max_turns=30, budget_usd=3.00):
items = [{"role": "developer", "content": DEVELOPER},
{"role": "user", "content": task}]
spent = 0.0
for turn in range(max_turns):
resp = client.responses.create(
model=model, input=items, tools=TOOLS,
reasoning={"effort": "medium"}, max_output_tokens=16000,
store=False, include=["reasoning.encrypted_content"],
)
spent += cost(model, resp.usage)
items += [o.model_dump(exclude_none=True) for o in resp.output]
calls = [o for o in resp.output if o.type == "function_call"]
if not calls:
return resp.output_text, spent, turn + 1
for c in calls:
items.append({"type": "function_call_output", "call_id": c.call_id,
"output": call_tool(c.name, json.loads(c.arguments))})
if spent >= budget_usd:
break
raise RuntimeError(f"stopped after {turn + 1} turns, ${spent:.3f} spent")
Why the loop is built this way:
- Output items go back in order, including reasoning items. For requests where
storeis false, as under Zero Data Retention, OpenAI's GPT-6.2 guide says to "pass the prior output items back in order, including encrypted reasoning items."include=["reasoning.encrypted_content"]asks for them. The alternative isprevious_response_idwith stored responses, which PoYo also documents. - The history is append-only. OpenAI warns that mid-conversation edits can make the Responses API drop reasoning items, which "can reduce answer quality and increase token use," and an edit also breaks the cached prefix.
- The budget is checked every turn, using the same price table as the bill.
We have not run this exact loop end to end on PoYo for this post. Run it on a small task first and confirm the tool calls and usage look as expected.
Streaming progress to the user
Long agent turns feel slow without feedback. Stream each turn, show text deltas, and take the final output from response.completed. These are the event types PoYo documents:
def stream_turn(model, items):
final = None
with client.responses.create(model=model, input=items, tools=TOOLS,
reasoning={"effort": "medium"}, max_output_tokens=16000,
store=False, include=["reasoning.encrypted_content"],
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":
final = event.response
elif event.type == "response.failed":
raise RuntimeError(event.response)
return final # same object as the non-streaming call: .output, .usage
Swap stream_turn into the loop in place of responses.create. Tool calls are read from final.output exactly as before.
Long context: 922K in, 128K out
GPT-6.2 accepts up to 922,000 input tokens per request. An agent can load a large part of a repository up front instead of reading files one by one. Three limits shape that choice:
- Every turn resends the history. A 200K-token snapshot over 20 turns is at least 4M input tokens. At Sol's $1.60 that is $6.40 uncached. With one cache write of the snapshot ($0.40) and 19 cache reads at $0.08 ($0.30), it is about $0.70.
- OpenAI's long-context tier starts above 272K input tokens. OpenAI's pricing page doubles input and cache rates and charges 1.5× output for the whole request past that line. Keep agent requests under 272K unless the task needs more, and check the model page for the PoYo rate that applies.
- Reasoning shares the output budget.
max_output_tokenscaps visible text plus reasoning. Ask for one file perwrite_filecall rather than a whole-repo rewrite.
Trim tool output before you append it: return the last 200 lines of a test run, not 20,000. That keeps the per-turn growth, and the bill, linear and small.
Prompt caching for agent sessions
OpenAI's caching guide sets these rules for GPT-6.2:
| Rule | Value |
|---|---|
| Cache read price | 0.05× input ($0.08 per 1M on Sol, $0.32 on Astra, on PoYo) |
| Cache write price | 1.25× input for the default 30-minute retention ($2 / $8 per 1M on PoYo) |
| Minimum cacheable prefix | 1,024 visible input tokens |
| Implicit breakpoint | End of the latest eligible message |
| Usage fields | usage.input_tokens_details.cached_tokens (reads), cache_write_tokens (writes) |
To make cache hits likely:
- Put stable content first. Developer message, then tool definitions, then the repository snapshot, then the task.
- Use a
developermessage, not top-levelinstructions. GPT-6.2 appendsinstructionsafterinput, so they would sit outside the prefix. - Never edit earlier items. Append tool outputs; don't rewrite history.
- Keep settings stable within a session. OpenAI's guide says to keep the prefix unchanged when you change settings between responses.
OpenAI also documents prompt_cache_options (explicit breakpoints and a 12-hour retention). PoYo's Responses schema does not list that field and is declared closed to extra fields (additionalProperties: false), so leave it out and rely on implicit caching. A best-case 25-turn session on Sol drops from $3.82 uncached to about $0.74; the arithmetic is in GPT-6.2 API pricing.
When to hand the run to Astra
Start every run on gpt-6.2-sol. If it stops at the turn limit with failing tests, restart the task on gpt-6.2-astra with a fresh item list. Do not switch the model inside the same conversation, because OpenAI says model changes can drop reasoning items. The routing math and a router are in GPT-6.2 Sol API vs GPT-6.2 Astra API. For a different vendor's take on the same loop, compare Gemini 4 Carbon API for coding agents.
Frequently asked questions
Does the GPT-6.2 API support function calling?
Yes, on /v1/responses. Define tools with type: "function", read function_call items from output, and send results back as function_call_output items with the same call_id.
Can I use GPT-6.2 API tools with Chat Completions?
No. OpenAI says GPT-6.2 supports Chat Completions, but tool calling requires Responses.
How do I stream a GPT-6.2 API agent turn?
Set stream: true on Responses, print response.output_text.delta events, and read tool calls and usage from the response.completed event.
How do I lower GPT-6.2 API costs in long agent sessions?
Keep a stable prefix (developer message, tools, snapshot) at the start, append instead of editing, trim tool output, and stay under 272K input tokens per request when you can.
Which GPT-6.2 model should run my coding agent?
Start with gpt-6.2-sol, which costs a quarter of Astra per token, and restart a failed run on gpt-6.2-astra.