Handle API Request Tool responses and errors
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:
Return a non-2xx status when the action does not complete. Keep the error body machine-readable and consistent:
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.
Successful order
Invalid product
Invalid quantity
Malformed JSON
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.
Dashboard
cURL
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.
Dashboard
cURL
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
For broader issues with tool selection, schemas, and model-visible responses, see Custom tools troubleshooting. For call-level failures, see Troubleshoot call errors.