Using Function Calling with GPT and Claude
What function calling and tools actually do
Function calling is how you let an AI model do more than chat. Instead of only generating text, the model can decide when to call a real function in your app, such as searching a database, checking the weather, creating a ticket, or fetching account data. In modern AI APIs, this is often called tools, and the idea is the same: the model picks a tool, your code runs it, then the model uses the result to answer the user.
This matters because GPT and Claude are strongest when they can combine language understanding with real actions. For example, a user might ask, “What’s my open invoice total this month?” The model should not guess. It should call your billing function, get the number, and return a precise answer.
The basic workflow
Whether you use GPT or Claude, the flow is usually:
- You send the user message plus a list of available tools.
- The model decides whether a tool is needed.
- If yes, it returns a structured tool call with arguments.
- Your application executes the function.
- You send the tool result back to the model.
- The model produces the final user-friendly response.
This pattern is powerful because the model stays in control of language, while your application stays in control of business logic and data access.
A simple example: weather lookup
Imagine you define a tool called get_weather with inputs like city and units. A user asks, “What’s the weather in Berlin right now?” The model can decide that text alone is not enough and trigger the tool with something like { city: "Berlin", units: "celsius" }. Your backend calls a weather API, returns the temperature and conditions, and the model turns that into a natural answer.
The key benefit is reliability. The model does not have to invent a weather result. It only formats the data your app gives it.
How GPT and Claude handle tools
GPT and Claude both support tool use, but the exact request and response shapes differ. If you are building against the OpenAI SDK, GPT tool calling is straightforward, and many Claude-compatible workflows now follow similar patterns. Claude is especially strong at multi-step reasoning with tools, while GPT is widely used in production apps for structured tool calls and broad SDK support.
If you want one API layer that works cleanly with both, 59API is a practical option. It provides cheap, pay-as-you-go access to Claude models like Opus, Sonnet, Haiku, and Fable, plus GPT models, and it is fully compatible with Claude Code, Codex, and any OpenAI SDK. The API base URL is https://api.59api.com, so you can plug it into existing tool-calling code without changing your app architecture.
What to pay attention to when designing tools
- Keep tool names clear: Use names like create_support_ticket instead of vague names like action1.
- Use strict schemas: Define exact inputs so the model knows what arguments are valid.
- Return compact results: Give the model only the data it needs, not a huge raw payload.
- Validate every call: Never trust model-generated arguments without server-side checks.
- Separate read and write actions: Tools that modify data should require stricter permissions.
These basics make your system safer and easier to debug.
Practical use cases for beginners
Once you understand the pattern, you can build useful apps quickly:
- Support assistants that search FAQs and create tickets.
- Sales assistants that look up CRM records and draft follow-ups.
- Developer assistants that inspect logs or run code helpers.
- Personal productivity tools that manage calendars, tasks, or notes.
Start with one or two tools, not ten. A small toolset is easier to test and gives you cleaner model behavior.
Why a low-cost relay like 59API helps
Tool calling can get expensive because each interaction may include multiple model turns: the original request, a tool call, and a final response. If you are experimenting, building prototypes, or running a production app with many users, model cost matters a lot. 59API is attractive because it offers low-cost, pay-as-you-go access and is described as one of the cheapest relays available, while still using native official-quality models with no downgrade. It also includes a referral rebate, which can further reduce cost as your usage grows.
That makes it easier to test tool workflows across GPT and Claude without being forced to cut corners on model quality.
Getting started today
If you already use an OpenAI SDK or Claude-compatible workflow, you can usually start by pointing your client to https://api.59api.com, then defining your tools exactly as you would in a normal function-calling setup. From there, test one scenario end to end: user message, tool decision, function execution, final answer.
If you are new to this, build a tiny demo first: a weather tool, a calculator tool, or a database lookup tool. That small loop will teach you almost everything you need to know about real AI integrations.
Want to keep your prototype affordable while using high-quality GPT and Claude models? Sign up for 59API and start building with tool calling on a budget.
Prêt à commencer ?
Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.
Inscription gratuite