Skip to main content
Tool calls let the model choose functions executed by your application. The model only generates the call intent and parameters; it does not access databases, send emails, or execute commands for you.

Call flow

  1. Send tool names, descriptions, and JSON parameter structures in the request.
  2. The model returns a tool call and parameters.
  3. The application validates parameters, permissions, and user intent.
  4. The application executes the tool and records audit information.
  5. Return the tool result to the model in a follow-up message to get the final answer.

Request example

Send to POST https://api.apione.ai/v1/chat/completions. Only use these fields when the target model and route support tool calls; check model parameters first.

Parsing and validation

The response content may be empty; tool requests are usually in choices[].message.tool_calls. Do not directly execute model-generated strings: parse JSON first, then validate tool names, field types, enums, lengths, and permissions.

Safety boundaries

  • Use an allowlist for tool names; reject unknown tools outright.
  • File, command, payment, deletion, and external messaging are high-risk operations that should require extra confirmation.
  • Recalculate user permissions on the server side; do not trust user IDs or amounts passed by the model.
  • Set execution timeouts, maximum return sizes, and rate limits.
  • Remove keys, internal error stacks, and irrelevant personal data from tool results.

Common issues

Complete Python example

The example executes a temperature conversion in code, then sends the result back to the model. First install dependencies, then follow Quickstart to set APIONE_API_KEY and a tool-capable APIONE_MODEL. Save as tool_demo.py and run python tool_demo.py.
The local function returns 77 degrees Fahrenheit for 25 degrees Celsius; the model’s final wording depends on the actual response. Each tool result’s tool_call_id corresponds to the original call’s id; you must retain the tool call message and all results. The example limits execution to four rounds and eight tool calls per round, with SDK retries disabled. Charges are based on actual request records. Next: Structured output, Model parameters, Troubleshooting, Request reliability.