Skip to main content
Function calling (also known as tool use) lets the model request the execution of an external function while generating a reply — for actions like querying a database, calling an API, or reading/writing files. OpenPAI fully supports all three protocols, and they interoperate.

OpenAI protocol

After executing the function, send the result back:

tool_choice

parallel_tool_calls

Newer models support calling multiple tools in parallel by default; tool_calls in the response is an array — execute each and return them all at once. To disable parallelism, set parallel_tool_calls: false.

Claude protocol

tool_choice (Claude)

Gemini protocol

Return the result:

Protocol interoperability

When you call Claude / Gemini models via OpenPAI’s OpenAI-compatible endpoint, OpenPAI automatically converts the Anthropic / Google tool-calling structures to OpenAI’s tools / tool_calls, and vice versa. You don’t need to worry about protocol differences — just pick one style.

Best practices

Detailed descriptions

The more specific a tool’s description, the better the model decides when to call it and what arguments to pass.

Strict schema

Use required and additionalProperties: false to keep the model from passing stray fields.

Handle errors gracefully

When a tool fails, return the error as a tool_result so the model can retry or change strategy.

Parallel calls

Execute multiple independent tools in parallel in one call to reduce latency.