response_format, tools, and tool_choice. Check model support first, then parse and validate results in your application.
JSON output
This example requires a model supporting JSON mode. Install dependencies using the SDK guide, setAPIONE_API_KEY and APIONE_MODEL, save as json_output.py, and run python json_output.py.
json_object requests JSON output. Your application still checks the finish reason, parses the result, and validates fields and allowed values. Asking for JSON in a prompt does not replace a schema constraint.
JSON Schema
response_format can also carry json_schema. Supported schema subsets and strict-mode behavior depend on the model. Check model parameters before choosing constraints, and recheck the schema when switching models.
Tool call flow
- Declare permitted functions and parameters in
tools. Usetool_choiceif needed, after confirming model support. - Read
choices[].message.tool_calls. There may be multiple calls, and ordinary text may be empty. - Keep the assistant message. Validate tool names, parse arguments, and check user permissions. Confirm external writes as required by your application before execution.
- Send each result as a
role: "tool"message, withtool_call_idmatching the original call’sid. - Request the model again with the updated history and read the final answer. Limit the number of tool-call rounds in the application.
Compatibility
Forunsupported_parameter, remove optional fields and verify a minimal chat request before restoring them individually. Recheck JSON, tools, and streaming when changing models. See the APIONE Chat reference for complete fields.
