59API

← Back to all guides

GPT and Claude Tool Calling: A Practical Quick Start

API · EN · 2026-10-29

The tool-calling loop in one minute

Function calling lets a model request an operation your application knows how to perform: checking an order, searching documentation, or creating a ticket. The model generates a tool name and arguments; your application validates them, executes the operation, and returns the result. The model then uses that result to answer the user.

The important boundary: a tool request is not execution permission. Your backend remains responsible for authentication, authorization, validation, and side effects.

1. Connect and choose your API format

59API provides low-cost, pay-as-you-go access to GPT, Claude, and other model families through one relay. Its API base URL is https://api.59api.com, with OpenAI SDK compatibility. Store your API key in an environment variable, never in browser code or a repository. When configuring an SDK, use the documented endpoint for your chosen protocol, including any required version prefix.

For this walkthrough, use OpenAI Chat Completions semantics for GPT, or Anthropic Messages semantics for Claude where that interface is supported. These formats are not interchangeable. OpenAI Responses uses another tool-message structure, so do not copy Chat Completions message handling into it.

Current model examples include GPT-6.1 Sol and Claude Sonnet 5.5. Select the exact API model identifier from 59API’s catalog and confirm tool support on your chosen route; a display name is not necessarily the request identifier.

2. Define one small, read-only tool

Start with get_order_status rather than a payment or deletion function. Give it a narrow description: “Retrieve the current status of an order the authenticated user is authorized to access.” Use this JSON Schema for its arguments:

{"type":"object","properties":{"order_id":{"type":"string","description":"The order identifier supplied by the user"}},"required":["order_id"],"additionalProperties":false}

For OpenAI Chat Completions, place the definition in tools as an object with type: "function" and a function object containing name, description, and parameters. The parameters value is the schema above. On routes supporting strict function schemas, add strict: true inside the function object; still validate arguments server-side.

For Anthropic Messages, each entry in tools instead contains name, description, and input_schema. Use the same schema as input_schema. Ask the model to request missing order IDs rather than inventing them.

3. Execute the OpenAI tool loop

4. Handle Claude’s different result format

With Anthropic Messages, inspect assistant content for tool_use blocks. Each carries an id, name, and input object. Preserve the complete assistant response content in history, execute the authorized calls, then send a user message containing tool_result blocks. Each result must include tool_use_id matching the original block’s id and content containing your result.

If several tools were requested together, return their results together in that next user message. For a failed execution, set is_error: true on the corresponding tool_result. Do not replace Claude’s result blocks with OpenAI role: "tool" messages.

5. Add guardrails and keep costs predictable

Set tool timeouts, cap loop iterations, and limit returned data. Treat tool output as untrusted data, not instructions. Never expose credentials or unrestricted SQL or shell execution. Require confirmation for destructive actions, and use idempotency keys before retrying writes.

59API positions itself among the cheapest relays, offering native official-quality models without downgrades and a referral rebate. Compare total task cost, including repeated context and tool results, rather than token rates alone. Sign up for 59API and test this read-only workflow before connecting production actions.

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