log in
consulting hosting industries the daily tools about contact

Claude Tool Use Will Bite You If You Think It's Just OpenAI Function Calling

Migrating from OpenAI function calling to Claude's tool use looks straightforward until it isn't. Here's where the mental model breaks down.

I spent a week migrating a client's AI assistant from GPT-4o to Claude Sonnet last month and hit enough surprises that I wanted to write them down. The Anthropic docs are decent, but they assume you're coming in fresh. If you're coming from OpenAI's function calling, you'll pattern-match on the wrong things and waste hours debugging behavior that isn't a bug - it's just a different model.

The short version: tool use in Claude is conceptually similar but behaviorally different in ways the docs undersell. Let me show you where it breaks.

What Tool Use Actually Is (In Plain Terms)

Both OpenAI and Anthropic give the model a way to say "I need external data before I can answer this" and hand control back to your code. You run the tool, return the result, and the model finishes its response. Same idea, same loop.

The difference is in how Claude thinks about that loop - and in a few API shape decisions that look minor but aren't.

The API Shape Is Close Enough to Be Dangerous

Here's a minimal OpenAI function calling setup in PHP:

$response = $openai->chat()->create([
    'model' => 'gpt-4o',
    'messages' => $messages,
    'tools' => [
        [
            'type' => 'function',
            'function' => [
                'name' => 'get_patient_labs',
                'description' => 'Fetch recent lab results for a patient',
                'parameters' => [
                    'type' => 'object',
                    'properties' => [
                        'patient_id' => ['type' => 'string'],
                        'days_back'  => ['type' => 'integer', 'default' => 30],
                    ],
                    'required' => ['patient_id'],
                ],
            ],
        ],
    ],
]);

$choice = $response->choices[0];
if ($choice->finishReason === 'tool_calls') {
    foreach ($choice->message->toolCalls as $call) {
        $args   = json_decode($call->function->arguments, true);
        $result = getPatientLabs($args['patient_id'], $args['days_back'] ?? 30);

        $messages[] = ['role' => 'assistant', 'content' => null, 'tool_calls' => [$call]];
        $messages[] = [
            'role'         => 'tool',
            'tool_call_id' => $call->id,
            'content'      => json_encode($result),
        ];
    }
}

Now here's the equivalent with Claude via the Anthropic PHP SDK:

$response = $anthropic->messages()->create([
    'model'      => 'claude-sonnet-4-5',
    'max_tokens' => 1024,
    'tools' => [
        [
            'name'        => 'get_patient_labs',
            'description' => 'Fetch recent lab results for a patient',
            'input_schema' => [
                'type' => 'object',
                'properties' => [
                    'patient_id' => ['type' => 'string'],
                    'days_back'  => ['type' => 'integer'],
                ],
                'required' => ['patient_id'],
            ],
        ],
    ],
    'messages' => $messages,
]);

if ($response->stopReason === 'tool_use') {
    $assistantContent = $response->content; // array of content blocks

    $toolResults = [];
    foreach ($response->content as $block) {
        if ($block->type !== 'tool_use') continue;

        $result = getPatientLabs($block->input['patient_id'], $block->input['days_back'] ?? 30);

        $toolResults[] = [
            'type'        => 'tool_result',
            'tool_use_id' => $block->id,
            'content'     => json_encode($result),
        ];
    }

    // This is the part people get wrong
    $messages[] = ['role' => 'assistant', 'content' => $assistantContent];
    $messages[] = ['role' => 'user',      'content' => $toolResults];
}

Spot the two things that will ruin your afternoon if you miss them.

Gotcha 1: Tool Results Go Back as user Role, Not a Dedicated Role

In OpenAI, tool results have their own role: tool. It's a first-class citizen in the message array.

In Claude, tool results go back in a user turn. The content field on that user message is an array of tool_result blocks. This is the one that broke my conversation history logic completely. I was appending tool results with role: tool and Claude was rejecting the request with a validation error that wasn't immediately obvious about why.

The mental model shift: Claude sees the tool result as "the user (or the environment) is responding to my request for information." OpenAI treats it as a separate channel. Neither is wrong, they're just different, and you can't swap them.

Gotcha 2: input Is Already Parsed, Not a JSON String

With OpenAI, tool_calls[n].function.arguments is a JSON string. You call json_decode() on it.

With Claude, block->input is already a PHP array (or stdClass, depending on your SDK). I had a json_decode() call sitting there from my OpenAI code and it silently returned null because you're trying to decode an array. That's a fun one to track down when your tool is getting called with no arguments.

Gotcha 3: The Assistant Message Must Include the Full Content Array

This tripped me up on multi-turn conversations. When Claude calls a tool, the response content is an array that might contain both a text block and one or more tool_use blocks. Claude will often say something like "Let me look that up" before the tool call.

When you're building the next turn's message history, you have to append the entire $response->content array as the assistant message content - not just the tool_use blocks, and not a string. If you strip out the text block and only keep the tool_use blocks, Claude gets confused about its own history. I saw this surface as the model refusing to continue, claiming it didn't have context it clearly had generated one turn earlier.

Gotcha 4: stop_reason vs finish_reason

Minor but annoying: OpenAI uses finish_reason: 'tool_calls'. Claude uses stop_reason: 'tool_use'. Not tool_calls, tool_use. I had a conditional checking for tool_calls that silently fell through and I burned 20 minutes wondering why my tools were never getting invoked.

Gotcha 5: Claude Is More Verbose About Calling Tools

This is behavioral, not structural, but it matters for production. Claude often generates a text block before or after a tool_use block explaining what it's doing. GPT-4o tends to go straight to the function call with no preamble.

For a healthcare client's internal tool I was building, this was actually fine - the users liked the narration. But if you're building something where you want clean JSON output from tool results with no extra text, you need to be explicit in your system prompt. Something like: "When you need to call a tool, call it immediately without explaining that you're going to call it."

Also worth knowing: Claude will sometimes return a final text response in the same content array alongside a tool_use block when it thinks it already has enough context for a partial answer. OpenAI doesn't do this. Your parsing loop needs to handle mixed content blocks.

Gotcha 6: tool_choice Works Differently

OpenAI lets you force a specific function with tool_choice: {type: 'function', function: {name: 'my_func'}}. Claude's equivalent is tool_choice: {type: 'tool', name: 'my_func'}. Same idea, different key name (tool not function). If you're auto-generating these payloads from a config object and you don't update the key, Claude will silently ignore the forced choice and do whatever it wants.

When I'd Reach for Claude's Tool Use

I've started preferring Claude for agentic workflows where the model needs to chain several tool calls and reason about the results. In my experience it's more careful about not hallucinating tool arguments - it'll ask a clarifying question rather than guess at a required parameter. For a biotech client running instrument queries through natural language, that conservatism is exactly what I want.

I'd also reach for Claude when the user-facing narration during tool calls adds value. The fact that it explains its reasoning before calling a tool is a feature for certain UIs.

When I Wouldn't

If you're deep in the OpenAI ecosystem - Assistants API, threads, fine-tuned models - the migration cost is real and the tool use differences are just part of a larger compatibility gap. Don't migrate for migration's sake.

Also, if you need streaming tool calls and you're parsing the stream incrementally, be aware that Claude's streaming tool use chunks arrive differently than OpenAI's. That's a whole separate post. I haven't loved either implementation, honestly.

The Bottom Line

The mental model difference that actually matters: OpenAI function calling feels like a remote procedure call that happens to live in the chat protocol. Claude tool use feels like the model genuinely pausing to ask the environment a question and waiting for an answer. Both get you to the same place, but the API shapes reflect those different philosophies in ways that will catch you if you're not looking.

Read the Anthropic message construction docs carefully before you write a single line of migration code. The 20 minutes you spend there will save you an afternoon of head-scratching.

Related

Need help shipping something like this? Get in touch.