Skip to main content

Tool Calling (Function Calling)

Tool calling allows models to invoke external functions, APIs, and tools during a conversation. The model decides when to call a function based on the user’s message and returns structured arguments you can use to execute the function in your application.
The Morpheus Inference API is fully OpenAI-compatible β€” tool calling works exactly like OpenAI’s function calling API. If you’ve used OpenAI tools before, you already know how to use this.

Supported Models

Most models on the Morpheus API support function calling. See the Available Models page for the full list β€” look for the Function Calling capability. Popular choices for tool calling:

How It Works

  1. Define tools β€” Describe available functions with names, descriptions, and JSON Schema parameters
  2. Send request β€” Include tools in your chat completion request
  3. Model responds β€” The model either answers directly or returns a tool_calls array with function names and arguments
  4. Execute functions β€” Run the requested functions in your application
  5. Return results β€” Send function results back to the model for a final response

Basic Example

Define a tool and let the model decide when to call it:

Complete Tool Calling Loop

In a real application, you execute the function and send the result back to the model:

Response Format

When a model decides to call a tool, the response includes a tool_calls array:
When finish_reason is "tool_calls", the model is requesting function execution. The content field may contain a brief message or be null β€” always check for tool_calls first regardless of whether content is present.

Multiple Tools

You can define multiple tools and the model will choose which to call:

Tips

The model uses the description field to decide when to call a function. Be specific about what the function does and when it should be used.
Help the model provide the right arguments by describing each parameter clearly, including format expectations and valid values.
Always check finish_reason β€” if it’s "tool_calls", execute the functions and send results back. The model may call multiple functions in sequence before giving a final answer.

Next Steps

Available Models

See which models support function calling.

Chat Completions API

Full API reference for chat completions.

Vision Guide

Send images to vision-capable models.

Quickstart

Get started with your first API call.