Use these patterns to keep tool-calling deterministic and debuggable.
Pattern 1: Chat Completions loop
- Send user message + tool definitions.
- If
finish_reason is tool_calls, execute each tool call.
- Send tool outputs back as
role: "tool" messages.
- Read final assistant answer.
Request (continuation)
Pattern 2: Responses loop
For /v1/responses, model tool calls appear as output items of type function_call.
Then send a follow-up request with function_call_output input items.
Request (follow-up)
Endpoint selection
- Prefer
/v1/chat/completions if you already use OpenAI-style message loops.
- Prefer
/v1/responses if your app is standardized on the Responses API.
- Use
/v1/messages if your app is Anthropic-native.
Last modified on July 26, 2026