Tool Calling
DEVUP AI supports OpenAI-compatible tool calling for models that expose this capability. By defining external tools (like APIs or database queries), you can allow the model to intelligently choose when and how to call them. Tool-call quality, feature support, and parameter compliance may vary by model.
Tool-calling flow
User request
Send messages and available tool definitions.
Model requests tool
Receive the requested tool name and generated arguments.
Validate & execute
Validate the tool name and arguments, then run the application-owned function.
Return tool result
Append a role: "tool" message using the matching tool_call_id.
Final answer
Send the updated conversation and receive the model’s final response.
Setup
Define a local function
First, define the function in your application that the model can call. This is a local demonstration function that returns static data. The application fully owns this logic.
Send tools to the model
Provide the tool definition in the request using JSON Schema. The model will determine if it needs to call the tool based on the user's message.
Execute and return results
After validating the tool name and parsing the JSON arguments, execute your local function. Append the assistant's message, followed by the tool result containing the matching tool_call_id.
The current temperature in San Francisco, CA is 60 degrees Fahrenheit.
Parallel tool calls
One reply can carry several entries in message.tool_calls. Run each call, then append one role: "tool" message per call, each with the tool_call_id of its call, before you send the next request. The loop in step 3 does this.
Set parallel_tool_calls: false to ask the model for at most one tool call per reply. Send parallel_tool_calls together with tools: on some models, parallel_tool_calls without tools is left out, with the notice parameter_not_supported.
tool_calls.parallel in GET /v1/models is true for models that can return several tool calls in one reply.
Streaming tool calls
With stream: true, tool calls arrive in choices[0].delta.tool_calls. Each entry has an index that identifies its call. The first entry of a call carries its id, type: "function" and function.name; the entries that follow with the same index carry the next parts of function.arguments.
Join the argument parts of each index in the order they arrive, and parse them after the stream ends. A choice whose reply calls tools ends with finish_reason: "tool_calls". Treat each id as an opaque string. As in every chat stream, when the model completes its reply the last chunk has an empty choices array and carries usage; see Streaming.
Tool execution safety
Security Best Practices
- Treat model-generated arguments as untrusted user input.
- Strictly allowlist executable tool names.
- Validate arguments rigorously against the JSON schema.
- Never execute arbitrary code or shell commands.
- Apply strict timeouts to prevent hanging executions.
- Handle tool failures gracefully and safely.
- Never expose secrets or credentials in the tool results.
- Limit result size to prevent context overflow.
Best Practices
Write clear and specific tool names and descriptions. The model's decision to invoke a tool depends heavily on them.
Use strict, minimal JSON schemas. Always validate all arguments on your application side before running any logic.
Keep the list of provided tools focused. Providing too many unrelated tools can degrade model reasoning.
Check the selected model's robust capabilities. Use deterministic settings like a lower temperature when appropriate.
Which models take tools
Each model in GET /v1/models shows what it supports for tool calling. A key that is not shown is not known yet.
supports.toolsistruefor models that taketools.- tool_choice shows, for each
tool_choicevalue whose handling is known, whether the model enforces it. A request with a value markedfalseis answered with the notice tool_choice_not_enforced. - tool_calls.chat_completions is
falsewhen tool calls for the model are served on /v1/responses: aPOST /v1/chat/completionsrequest withtoolsthen returns HTTP 400 use_responses_api. It istruewhen they are served on/v1/chat/completions. tool_calls.parallelistruewhen the model can return several tool calls in one reply (see Parallel tool calls).
A tool_choice of "required" or a named function without tools returns HTTP 400 missing_tools.
Supported capabilities
tool_choice: "auto"tool_choice: "none"