Build an AI agent with the KeyoAPI chat API
An AI agent combines model requests with application code that tracks state, runs tools and checks results. KeyoAPI supplies the model API; your application owns the execution loop. Start with a small planning request, add validated actions, and set a budget for every task.
Choose an API model for your agent
For a first evaluation, gpt-6.1-sol is a lower-cost chat candidate than gpt-6-astra at the checked default-group rates. Claude Opus 5.5 and Fable 5.1 provide another pair to test on coding or planning tasks. Compare GPT-6.1 Sol vs GPT-6 Astra and Fable 5.1 vs Opus 5.5 for prices and evaluation criteria. Those rate differences do not prove which model will complete your task best.
The basic endpoint is POST /v1/chat/completions. Create an API key in the console and keep it on your server. Check tools, tool_choice, streaming and other optional parameters against the chosen model route before depending on them. You can begin with ordinary messages and a planner response while you verify the advanced contract.
Make a bounded planning request
This example asks for a plan only. It does not execute code, call an external tool or create an agent session. Your application must parse the response, validate its structure and decide which actions it can run.
curl https://www.keyoapi.xyz/v1/chat/completions \
-H "Authorization: Bearer $KEYO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-6.1-sol","messages":[{"role":"system","content":"Return a JSON object with goal, steps and stop_condition. Plan at most three steps. Do not claim to have executed any action."},{"role":"user","content":"Plan a support assistant that searches an approved help center and drafts an answer with source links."}],"max_tokens":600}'
Implement the execution loop in your application
Store a task ID, user goal, selected model, validated plan and previous tool results. Limit available tools to explicit schemas and authorized data. Treat the model's proposed arguments as input to validate, then run the selected tool in application code and attach its result to the next request using the route's documented message format.
Stop when the acceptance condition is met, a tool fails repeatedly, the maximum turn count is reached or the budget is exhausted. Log each request's usage and each action's result. Avoid replaying actions with side effects when retrying a timed-out model request; use application-level action IDs and idempotency where appropriate. Test a failed tool response as well as a successful path.
Budget for the whole agent task
Agent cost is the sum of every model turn, including retries and repeated context. At the checked Sol default-group rates, a single 10,000-input and 2,000-output turn costs about $0.007354. Ten turns with that identical token mix cost about $0.07354; real conversations often grow, so log actual usage rather than multiplying only the first turn.
Track cost per accepted task, execution errors and human corrections. Summarize old tool output when it no longer needs to remain verbatim, cache reusable application data, and test any cheaper model against the same acceptance rules. Use the gpt-6.1-sol model page for a starting model guide and the pricing page for current billing-group rates.
FAQ
Does KeyoAPI run my agent tools?
The chat API generates model responses. Your application manages the agent loop, tool execution, state and acceptance checks.
Do all chat models support tool calling?
Do not assume that. Check the selected model and route, then verify a small tool-call request before deploying the feature.
How do I compare agent models fairly?
Use the same tasks, tools, context and budgets. Compare completed tasks, corrections, time and the total bill including retries, not only per-token rates.