59API

← Back to all guides

Function Calling with GPT and Claude: A Practical Guide

API · EN · 2026-10-04

What Function Calling Means

Function calling, also called tool use, lets an AI model request work from your application instead of guessing an answer. For example, a support assistant can call a function that looks up an order, a travel bot can search available flights, or a coding agent can read a repository file. The model decides which approved tool to use and supplies structured arguments. Your server performs the real action, then sends the result back to the model so it can produce a useful response.

This is important because GPT and Claude do not directly access your private database, internal APIs, or live business systems. Tool calling creates a controlled bridge between the model and those systems. The model handles language and intent; your application remains responsible for permissions, execution, and final validation.

The Basic Tool-Calling Loop

The workflow is similar for OpenAI-compatible GPT APIs and Claude APIs. First, define the tools your application allows. Each tool needs a name, a clear description, and an input schema describing valid parameters. Next, send the user message plus those tool definitions to the model. If a tool is needed, the model returns a tool call rather than a final natural-language answer.

GPT Function Calling in Practice

With the OpenAI SDK, tools are generally supplied in a tools array. A function tool includes a type of function, a function name, a description, and JSON Schema parameters. When GPT chooses a function, the response includes a tool call with JSON arguments. Do not execute those arguments blindly. Parse the JSON, reject missing or unexpected values, and enforce business rules before accessing a downstream system.

For example, an order-status tool should accept only a validated order identifier. It should derive the customer identity from the authenticated session, not from a model-provided customer_id. This prevents a prompt or malformed tool argument from exposing another customer's data. After your server returns a small structured result, such as status, carrier, and tracking URL, GPT can turn it into a readable answer.

Claude Tool Use in Practice

Claude uses the same core pattern but names the concepts differently. You provide tools with an input_schema. When Claude needs one, it returns a tool_use content block containing an id, tool name, and input object. Your application executes the matching operation and responds with a tool_result content block linked to that tool-use id. Claude can then continue the conversation using the returned data.

Keep tool descriptions concrete. Instead of describing a tool as “handles customer information,” explain exactly what it returns, which fields are required, and when it should be used. Clear descriptions reduce incorrect calls and make multi-step tasks more reliable. For write operations, such as sending an email or issuing a refund, instruct the model to ask for confirmation first and require your backend to enforce that confirmation.

Choose a Safe, Cost-Effective Setup

Start with read-only tools while you test behavior. Log every tool name, argument set, result, latency, and error, while removing secrets and personal data from logs. Set timeouts and rate limits for external services. Return concise, predictable data rather than a large raw API response, because smaller tool results are cheaper and easier for a model to use accurately.

59API is a practical option when you want to experiment with both GPT and Claude tool workflows without maintaining separate billing paths. Its API base URL is https://api.59api.com, and it is compatible with OpenAI SDKs as well as workflows used by Claude Code and Codex. Developers can use native official-quality Claude Opus, Sonnet, Haiku, Fable, and GPT models on a pay-as-you-go basis, which helps keep prototyping and production tool calls affordable.

Use the model best suited to each job: a fast lower-cost model for simple lookups, and a more capable model for complex planning or ambiguous requests. Measure tool-call success rate and total cost per completed task before changing models. To begin building with a low-cost relay and access a referral rebate, sign up for 59API and point your compatible client to its API base URL.

Pricing · Docs

Ready to get started?

Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.

Sign up free