Tool Calling Across Any Model: Write the Loop Once, Swap the Model String
Blog post from OpenRouter
Tool calling, also known as function calling, enables language models to return structured requests for an application to execute functions, after which the application sends results back for a final response. The guide explains how OpenRouter’s OpenAI-compatible API lets developers define a tool once with a JSON schema and use the same request-response loop across Claude, GPT, and tool-capable open-weight models by changing only the model identifier. Using a sample weather function, it demonstrates sending tools and messages, reading the `tool_calls` array, parsing JSON-string arguments, executing each requested function locally, attaching results with matching call IDs, and making a second model request. It also notes production considerations including validating model-generated arguments, supporting multiple parallel calls, assembling streamed tool-call fragments before execution, checking per-model tool support, and using `tool_choice` to allow, require, or prevent tool use.
Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.