#### Advanced API usage

# Troubleshooting tool call IDs

When a Grok model calls a function, the call has a `call_id`. Your next request must send the result back with the same `call_id`. Most of the mistakes below still return `200`, but the model can no longer tell which result answers which call.

The examples use the Responses API (`/v1/responses`), which we recommend for tool calling.

## Leaving the call ID empty

A `function_call_output` has `"call_id": ""`. The API rejects a missing `call_id`, but it accepts an empty one. The usual cause is an unset field that serializes as `""`.

To fix it, copy the `call_id` of the `function_call` into its result:

```json addedLines="10"
[
  {
    "type": "function_call",
    "call_id": "call-5faadddf-0",
    "name": "get_temperature",
    "arguments": "{\"location\":\"Paris\"}"
  },
  {
    "type": "function_call_output",
    "call_id": "call-5faadddf-0",
    "output": "{\"temperature\":15}"
  }
]
```

To confirm the fix, log the `input` of a follow-up request and check that no `call_id` is empty.

## Using the item ID instead of the call ID

A `function_call` item has two IDs: `id` and `call_id`. Your result carries the value of `id`, so it matches no call.

To fix it, read `call_id`, not `id`:

```json addedLines="11"
[
  {
    "type": "function_call",
    "id": "fc_9a1e6c0e_0",
    "call_id": "call-5faadddf-0",
    "name": "get_temperature",
    "arguments": "{\"location\":\"Paris\"}"
  },
  {
    "type": "function_call_output",
    "call_id": "call-5faadddf-0",
    "output": "{\"temperature\":15}"
  }
]
```

To confirm the fix, check that no `call_id` in your results starts with `fc_`.

## Not answering every call exactly once

One response can hold several `function_call` items. Your next request answers only some of them, or answers one of them twice.

To fix it, send exactly one result for each call, all in the same request. If a tool fails, send the error as its `output`:

```json addedLines="4,9"
[
  {
    "type": "function_call_output",
    "call_id": "call-5faadddf-0",
    "output": "{\"temperature\":15}"
  },
  {
    "type": "function_call_output",
    "call_id": "call-5faadddf-1",
    "output": "{\"error\":\"timed out\"}"
  }
]
```

To confirm the fix, count the calls in a response and the results in your next request. The two numbers must match, and no `call_id` may repeat.

To get one call at a time, set `parallel_tool_calls` to `false`.

## Dropping a call or changing its ID

A result has a `call_id` that matches no call in the conversation. This happens when your code leaves out the `function_call` item, or when storage shortens or rewrites the ID.

To fix it, send every output item of a response back exactly as it arrived, then add your results. [Troubleshooting reasoning](/developers/advanced-api-usage/troubleshooting-reasoning#dropping-the-reasoning-items) shows the full history.

```json addedLines="4,10"
[
  {
    "type": "function_call",
    "call_id": "call-5faadddf-0",
    "name": "get_temperature",
    "arguments": "{\"location\":\"Paris\"}"
  },
  {
    "type": "function_call_output",
    "call_id": "call-5faadddf-0",
    "output": "{\"temperature\":15}"
  }
]
```

To confirm the fix, check that the `call_id` of each result also appears on a `function_call` earlier in the conversation.

## Fix it with a coding agent

Paste the following into your coding agent, or save it as a skill, for example as `.grok/skills/fix-grok-tool-call-ids/SKILL.md` for [Grok Build](/build/features/skills-plugins-marketplaces). It finds these mistakes in your code and fixes them.

```text
---
name: fix-grok-tool-call-ids
description: >-
  Find and fix code that sends wrong tool call IDs to the Grok API
  (/v1/responses). Use when a model repeats tool calls or mixes up tool
  results.
---

# Fix tool call IDs in /v1/responses requests

Each function_call in a response has a call_id. The next request must hold
exactly one function_call_output for each call, with the same call_id.

A correct follow-up after two calls:

  "input": [
    {"role": "user", "content": "<the question>"},
    {"type": "function_call", "id": "fc_...", "call_id": "call-1",
     "name": "<tool_a>", "arguments": "<as received>"},
    {"type": "function_call", "id": "fc_...", "call_id": "call-2",
     "name": "<tool_b>", "arguments": "<as received>"},
    {"type": "function_call_output", "call_id": "call-1",
     "output": "<result a>"},
    {"type": "function_call_output", "call_id": "call-2",
     "output": "<result b>"}
  ]

Send back every other output item of the response unchanged too. With
previous_response_id, send only the function_call_output items.

Most of these mistakes return HTTP 200, so check the request bodies, not
the status codes.

1. Find where the code reads function_call items from a /v1/responses
   response and where it builds function_call_output items.

2. Check each point and fix it with the smallest change that works.
   a. call_id is empty. Fix: copy it from the function_call.
   b. call_id holds the item id ("fc_..."). Fix: use call_id.
   c. A call has no result, or has two. Fix: send exactly one result for
      each call in the same request. Send a tool error as the output.
   d. A function_call is left out, or an ID is shortened or rewritten.
      Fix: keep the items and their IDs unchanged.

3. Test it. Capture the request that follows a response with two calls.
   Each call must have exactly one result with the same, non-empty
   call_id.

4. Report what was wrong and what you changed. Do not change models,
   prompts, or tools.
```
