PRODUCTION USE CASE

LLM API for function calling

A sales assistant can look up an account, calculate a quote, and create a draft order. The user's request should call lookup_account first, then calculate_quote. create_order is unavailable until a human confirms the exact draft.

Validated function call connecting an LLM response to an application action
LLM API for function calling

Production recipe

API, primary model, and failover configuration

Production choiceRecommendationWhy
APIPOST /v1/chat/completionsOpenAI-compatible server-side request
Primary modelgpt-5.6-terraTerra is the default for reliable tool selection and multi-step argument construction without using the flagship on every call.
Fallback modelgpt-5.4Use gpt-5.4 for one-tool read-only requests. Escalate to Sol only for ambiguous plans involving several dependent tools.
Escalation modelgpt-5.6-solUse only when the primary route fails the defined quality or complexity boundary
Output contractValidated tool callsValidated tool calls followed by a draft quote; no external order creation before confirmation.
01
Scenario

Function calling in a production application

A sales assistant can look up an account, calculate a quote, and create a draft order. The user's request should call lookup_account first, then calculate_quote. create_order is unavailable until a human confirms the exact draft.

The model proposes tool calls; the application validates schemas, authorization, and state before execution. Tool errors are returned as structured results, and identical invalid calls are not retried.

02
Architecture

How the function calling workflow operates

  • Expose only tools allowed in the current state.
  • Let the model select a tool and propose arguments.
  • Validate every argument and permission in application code.
  • Execute with an idempotency key where writes are possible.
  • Return a structured result and continue until a bounded stop condition.
03
API request

Call gpt-5.6-terra through LLMFly AI

Send the request from your server. Replace the example content and placeholder tool schema with data and tools from your application.

request.exampleCopy-ready
curl https://app.llmfly.ai/v1/chat/completions \
  -H "Authorization: Bearer $LLMFLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-terra",
    "messages": [
      {"role": "system", "content": "Use the available tools to prepare a quote. Never create an order until the user confirms the exact draft. Do not invent account IDs or prices."},
      {"role": "user", "content": "Prepare a quote for 25 seats for Acme's current plan."}
    ],
    "tools": [{"type": "function", "function": {"name": "YOUR_TOOL", "description": "Replace with the tool contract for this workflow", "parameters": {"type": "object", "properties": {}, "additionalProperties": false}}}]
  }'
04
Model choice

Why gpt-5.6-terra is the primary model

Terra is the default for reliable tool selection and multi-step argument construction without using the flagship on every call.

Use gpt-5.4 for one-tool read-only requests. Escalate to Sol only for ambiguous plans involving several dependent tools.

05
Acceptance

Acceptance checks for function calling

MetricPass condition
Correct tool-selection rateThe model calls the required tool and avoids tools when none is needed
Valid-argument rateArguments pass schema, range, identifier, and authorization validation
Recovery after tool errorsA recoverable structured error leads to a corrected call rather than the same retry
Unsafe-call rateNo consequential tool executes without required permission or confirmation
06
Failure handling

Failures to handle before deployment

  • Executing unvalidated arguments
  • Retrying the same invalid call
  • Using overlapping tool descriptions
  • Letting text bypass permissions
07
Output

Returned output and run records

Validated tool calls followed by a draft quote; no external order creation before confirmation.

Record the model ID, request ID, token usage, retries, validation result, and final disposition for every production run.

Frequently asked questions

What metric should I track first?

Track whether the model chose the correct tool or correctly chose no tool before argument details.

Should tool arguments be trusted?

No. Validate types, required fields, ranges, identifiers, and authorization.

How should tool errors be returned?

Return a concise structured error without exposing secrets or internal traces.

Test this setup with your own inputs

Compare the primary and fallback models with the same requests, tools, and validation rules.

Compare models