Skip to main content
Tool calling (also known as function calling) enables models to intelligently select and use external tools based on user input. You can build agents that access APIs, retrieve real-time data, or perform actions—all through OpenAI-compatible tool specifications. How it works:
  1. Define tools using JSON Schema (name, description, parameters)
  2. Model analyzes the query and decides whether to call a tool
  3. If needed, model returns structured tool calls with parameters
  4. You execute the tool and send results back for the final response

Quick example

Define tools and send a request - the model will return structured tool calls when needed: Initialize the client:
Define the tools and make the request:
For best results with tool calling, use a low temperature (0.0-0.3) to reduce hallucinated parameter values and ensure more deterministic tool selection.

Defining tools

Tools are defined using JSON Schema format. Each tool requires:
  • name: Function identifier (a-z, A-Z, 0-9, underscores, dashes; max 64 characters)
  • description: Clear explanation of what the function does (used by the model to decide when to call it)
  • parameters: JSON Schema object describing the function’s parameters
Write detailed descriptions and parameter definitions. The model relies on these to select the correct tool and provide appropriate arguments.

Parameter types

JSON Schema supports: string, number, integer, object, array, boolean, and null. You can also:
  • Use enum to restrict values to specific options
  • Mark parameters as required or optional
  • Provide descriptions for each parameter
  • Reuse subschemas via $defs / definitions and $ref, including recursive references (e.g. linked lists, trees, mutually recursive types)
  • Carry $id, $schema, and other annotation keywords (no external fetches are performed)
The same JSON Schema feature set is supported in tool parameters and in response_format={"type": "json_schema", ...}. See JSON Schema Support for the full list, including the rules for resolving $ref and how to reach definitions placed inside nested subschemas.
A common shape produced by pydantic v2, Instructor, and LangChain TypeAdapter. The $defs block holds the reusable subschemas and properties reference them by $ref:

Additional configurations

tool_choice

The tool_choice parameter controls how the model uses tools:
  • auto (default): Model decides whether to call a tool or respond directly
  • none: Model will not call any tools
  • required: Model must call at least one tool
  • Specific function: Force the model to call a particular function
Some models support parallel tool calling, where multiple tools can be called in a single response. Check the model’s capabilities before relying on this feature.

Streaming

Tool calls work with streaming responses. Arguments are sent incrementally as the model generates them:

Troubleshooting

  • Check that your tool descriptions are clear and detailed
  • Ensure the user query clearly indicates a need for the tool
  • Try using tool_choice="required" to force tool usage
  • Verify your model supports tool calling (check supportsTools field)
  • Add more detailed parameter descriptions
  • Use lower temperature (0.0-0.3) for more deterministic outputs
  • Provide examples in parameter descriptions
  • Use enum to constrain values to specific options
  • Always validate tool call arguments before parsing
  • Handle partial or malformed JSON gracefully in production
  • Use try-catch blocks when parsing tool_call.function.arguments
The schema in parameters (or response_format) is reaching a $ref Fireworks cannot resolve. Common causes:
  • External $ref URI (e.g. https://example.com/schema.json). Only in-document JSON Pointer fragments (#/...) are supported. Inline the referenced subschema or hoist it into $defs.
  • Wrong fragment path, e.g. #/components/schemas/Foo when the document has no components key. Match the pointer to the actual document layout.
  • Older deployment image. Recursive $ref, root $id, and nested $defs placed under a property all became supported in mid-2026 and earlier images returned 400 on those shapes. If you control a self-hosted/dedicated deployment, redeploy on a current image.
For the full set of supported reference forms, see JSON Schema Support.

Next steps

Structured Outputs

Enforce JSON schemas for consistent responses

Text Models

Learn about chat completions and other APIs

Deployments

Deploy models on dedicated GPUs

API Reference

Full chat completions API documentation