Handle API Request Tool responses and errors

Design response contracts, recover from failures, and inspect tool results without misleading the caller.

An API Request Tool should return enough structured information for the assistant to distinguish a completed action from a rejected or failed request. Use HTTP status codes for success and failure, return JSON consistently, and give each error a stable code and actionable message.

Design the response contract

Return a 2xx status only when the requested action succeeds. The coffee-order quickstart endpoint returns 201 Created with the server-calculated total and a mock order number:

1{
2 "success": true,
3 "requestId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
4 "orderId": 47730,
5 "productName": "House coffee beans",
6 "quantity": 2,
7 "totalCents": 3600,
8 "totalDisplay": "$36.00",
9 "message": "Your mock order for 2 House coffee beans was accepted for $36.00."
10}

Return a non-2xx status when the action does not complete. Keep the error body machine-readable and consistent:

1{
2 "success": false,
3 "requestId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
4 "error": {
5 "code": "VALIDATION_ERROR",
6 "message": "Request body failed validation.",
7 "details": [
8 {
9 "field": "productId",
10 "code": "INVALID_ENUM_VALUE",
11 "message": "productId must be one of: coffee-beans, tea-sampler, ceramic-mug."
12 }
13 ]
14 }
15}

The API Request Tool treats a non-2xx response as a failed request. If a backoff plan is configured, the status code also determines whether the request is eligible for a retry. See Handle latency and retries before enabling retries.

Calculate prices, availability, permissions, and other authoritative values on your server. Do not ask the model to calculate or invent them.

Test successful and failed responses

Test the destination API directly before involving an assistant. This separates endpoint behavior from tool selection, schema, prompting, and voice-call behavior.

$curl --request POST \
> --url https://vapi-docs-orders.val.run/ \
> --header "Content-Type: application/json" \
> --include \
> --data '{
> "customerName": "Alex",
> "productId": "coffee-beans",
> "quantity": 2
> }'

Expect HTTP 201, success: true, a five-digit orderId, and a server-calculated totalDisplay of $36.00.

These errors are successful tests because the endpoint rejects bad input with the expected status and structured response.

Decide how the assistant should recover

Add explicit failure behavior to the assistant’s system prompt. The assistant must not claim that an order succeeded unless the tool returned a successful response.

Failure-handling instructions
When createCoffeeOrder fails, do not say that the order was accepted and do not invent an order number or total.
If the error identifies an invalid field, explain the allowed value in plain language, collect the corrected value, read the complete order back, and get confirmation before calling createCoffeeOrder again.
For a timeout, connection failure, or server error, apologize and explain that the order was not confirmed. Offer to try again, but call createCoffeeOrder again only after the caller agrees.

Open the coffee-order assistant in the Dashboard, add the instructions above to its System Prompt, then publish the assistant.

Use a system-role request-failed message when the model should adapt its response to the returned error and conversation context. Use an assistant-role message only when the same fixed sentence is appropriate for every failure. See Keep the caller informed for message configuration.

Inspect a call

After a test call, inspect the tool arguments and result before changing the schema or prompt.

Open Logs, select the call, and inspect its messages and tool-call entries. Confirm:

  • The assistant called the expected tool.
  • The model-generated arguments contain the confirmed customer name, product ID, and quantity.
  • The tool result contains either the accepted order or the structured error.
  • The assistant did not claim success after a failed request.

The call artifact does not show the final HTTP request after Vapi resolves Liquid values and merges static fields. Use logs from the destination API to inspect final headers and body values. Correlate the coffee endpoint’s requestId with its X-Request-Id response header and server logs when investigating a specific request.

Diagnose common failures

SymptomCheck first
Tool is not calledConfirm the exact tool name appears in the prompt, its description states when to use it, and it is attached to the assistant.
Tool arguments are missing or incorrectCheck property descriptions, types, required fields, enums, and the confirmation instructions.
Endpoint returns 400 or 415Check the body shape, JSON encoding, method, and Content-Type.
Endpoint returns 401 or 403Check the selected credential and destination permissions. Do not add a second manual Authorization header.
Endpoint returns 422Read the structured field details, correct the caller-provided value, and reconfirm before another tool call.
Endpoint returns 429 or 5xxTreat it as a transient or server-side failure. Retry only if the operation is safe to repeat.
Tool succeeds but the assistant gives the wrong resultMake the response fields unambiguous, instruct the assistant to use server-calculated values, and inspect the tool result in the call.
Request times outCompare the configured timeout with destination latency and add a delayed message. Do not use a longer timeout to hide an unreliable API.

For broader issues with tool selection, schemas, and model-visible responses, see Custom tools troubleshooting. For call-level failures, see Troubleshoot call errors.