59API

← 返回教程列表

Tool Use vs Function Calling: A Real API Example

API 使用 · EN · 2026-08-05

Tool use and function calling, in plain English

Tool use means an AI model can ask your app to do something it cannot do reliably on its own: look up a database record, fetch live weather, calculate a price, or create a ticket. Function calling is the structured way many APIs expose that ability. Instead of hoping the model writes a perfect sentence, you give it a list of allowed functions and a schema for the inputs.

That difference matters. A normal text answer is free-form. A function call is machine-readable, so your backend can validate it before taking action. In practice, that gives you safer workflows, cleaner logs, and fewer errors when the model needs external data.

A good rule: if the answer depends on live data, private data, or exact computation, use a tool instead of asking the model to guess.

A hands-on example: order status lookup

Imagine a support chatbot that answers, "Where is my order?" You should not let the model invent a status. Instead, define one function: check_order_status. Here is the schema you would pass to an OpenAI-compatible API:

Function schema: {"type":"function","function":{"name":"check_order_status","description":"Look up the current status of an order by order_id","parameters":{"type":"object","properties":{"order_id":{"type":"string"}} ,"required":["order_id"],"additionalProperties":false}}}

Now connect your client. If you are using an OpenAI SDK, point the base URL at 59API:

Client setup: const client = new OpenAI({ baseURL: 'https://api.59api.com', apiKey: process.env.API_KEY });

Then send a user message plus the function definition. If the user says, "Check order A123," the model should return a tool call, not a final answer. A typical response looks like this in concept: it selects check_order_status and passes {"order_id":"A123"}.

Your server receives that call, validates the input, and runs the real function. For example:

Internal logic: getOrderStatus('A123')

Suppose your database returns: shipped, tracking number 940011. You then send that result back to the model as tool output. The model can now write a human-friendly reply: "Your order A123 has shipped. Tracking number 940011 is active."

This two-step loop is the heart of reliable tool use: the model decides when to use the tool, and your code decides how the tool actually runs.

Best practices that make function calling work well

Keep your schemas narrow. If a tool only needs an order ID, do not expose twenty optional fields. Smaller schemas reduce confusion and improve call accuracy. Also set additionalProperties to false when possible, so the model cannot invent extra arguments.

Another practical tip: use cheaper models for simple routing and stronger models for complex orchestration. A small model can often choose the right tool, while a larger model may be better at multi-step reasoning after the tool returns.

Why 59API is a smart way to test this

Tool use loops can burn tokens quickly because each call adds another request and another response. That is exactly where a low-cost relay helps. 59API gives developers pay-as-you-go access to Claude models like Opus, Sonnet, Haiku, and Fable, plus GPT models, with official-quality native models and no downgrade. It is also compatible with Claude Code, Codex, and any OpenAI SDK, so you can keep the same function-calling pattern while swapping providers.

With the API base URL at https://api.59api.com, you can prototype a function-calling chatbot, an internal ops assistant, or a coding agent without paying premium rates. If you are iterating fast, the low entry cost and referral rebate make experimentation easier, especially when you need to test several tool schemas or compare model behavior side by side.

If you want to build with real tool use instead of toy examples, sign up for 59API and start testing function calling with live models at a much lower cost.

价格 · 接入文档

准备好开始了吗?

几分钟接入 Claude 与 GPT,全网超低价,原生不降智。立即注册即可领取 API 密钥。

免费注册