{
  "openapi": "3.1.0",
  "info": {
    "title": "CallHuman API",
    "version": "1.0.0",
    "summary": "Phone a person, read a message and get back the option they choose.",
    "description": "CallHuman places a phone call from your own number, reads your message and returns the option the person chooses — by keypress or by voice. Responses are asynchronous: creating a call returns an ID immediately and the result arrives at your webhook (or by polling).\n\nFixed behaviour: with options, the menu is repeated twice if there is no valid answer, the person has 10 seconds to answer, unanswered calls are retried twice 5 minutes apart and expire after 1 hour. One-way messages (no options) get a single attempt. Voicemail is never left. Only answered calls count towards your plan.\n\nDocs for AI assistants: https://www.callhuman.es/llms-full.txt",
    "contact": {
      "name": "CallHuman",
      "url": "https://www.callhuman.es",
      "email": "hello@callhuman.es"
    }
  },
  "servers": [
    {
      "url": "https://api.callhuman.es/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "tags": [
    {
      "name": "Calls",
      "description": "Create calls and read their results."
    }
  ],
  "paths": {
    "/calls": {
      "post": {
        "operationId": "createCall",
        "tags": [
          "Calls"
        ],
        "summary": "Create a call",
        "description": "Calls the person and reads the message. With `options`, the person answers by keypress or voice and you get the chosen option back. Only transactional calls are allowed: before calling we check what the person will hear and reject marketing, sales, scams and unsolicited messages (`call_not_allowed`). Validation order: 401 → 402 → 403 → 429 → 422.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Optional unique key, any string up to 255 characters (for example `booking-1042-confirmation` or a UUID). Repeating a request with the same key within 24 hours returns the original response — even if the body changed — and never places a second call.",
            "schema": {
              "type": "string",
              "maxLength": 255
            },
            "example": "bk_1042-reminder"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCallRequest"
              },
              "examples": {
                "booking": {
                  "summary": "Booking confirmation with replies",
                  "value": {
                    "to": "+34600111222",
                    "language": "en",
                    "message": "Hi! This is La Plaza about your table for 4 tonight at 8:30 pm.",
                    "options": [
                      {
                        "label": "Confirm",
                        "reply": "Perfect, see you tonight!"
                      },
                      {
                        "label": "Cancel",
                        "reply": "No problem, your booking is cancelled."
                      }
                    ],
                    "webhook_url": "https://laplaza.example/hooks/callhuman",
                    "metadata": {
                      "booking_id": "bk_1042"
                    }
                  }
                },
                "otp": {
                  "summary": "One-way message (verification code)",
                  "value": {
                    "to": "+14155552671",
                    "message": "Your verification code is 4 8 2 9. Again, 4 8 2 9."
                  }
                },
                "submenu": {
                  "summary": "Menu with a submenu",
                  "value": {
                    "to": "+34600555666",
                    "message": "Hi! Your order 1042 for 45 euros, cash on delivery, ships tomorrow.",
                    "options": [
                      {
                        "label": "Confirm",
                        "reply": "Great, it ships tomorrow."
                      },
                      {
                        "label": "Cancel",
                        "reply": "Your order is cancelled."
                      },
                      {
                        "label": "Change something",
                        "options": [
                          {
                            "label": "Change the address",
                            "reply": "We'll text you a link to change it."
                          },
                          {
                            "label": "Deliver another day",
                            "reply": "We'll call you to pick a day."
                          }
                        ]
                      }
                    ],
                    "webhook_url": "https://shop.example/hooks/callhuman"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Call accepted. The result arrives at `webhook_url` or via `GET /calls/{id}`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CallCreated"
                },
                "example": {
                  "id": "call_x9f2k",
                  "status": "queued"
                }
              }
            }
          },
          "401": {
            "description": "Missing, revoked or expired API key. Create a new one in your dashboard under API keys.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "code": "invalid_api_key",
                    "message": "Missing, revoked or expired API key. Create a new one in your dashboard under API keys.",
                    "docs_url": "https://www.callhuman.es/docs/errors#invalid_api_key"
                  }
                }
              }
            }
          },
          "402": {
            "description": "This project does not have an active plan. Subscribe at https://www.callhuman.es/billing to enable calls.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "code": "subscription_required",
                    "message": "This project does not have an active plan. Subscribe at https://www.callhuman.es/billing to enable calls.",
                    "docs_url": "https://www.callhuman.es/docs/errors#subscription_required"
                  }
                }
              }
            }
          },
          "403": {
            "description": "`project_suspended`: calls are paused for a security review (too many non-transactional calls).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "code": "project_suspended",
                    "message": "Calls are paused for this project while we review recent messages that looked like marketing. Reply to our email or write to hello@callhuman.es.",
                    "docs_url": "https://www.callhuman.es/docs/errors#project_suspended"
                  }
                }
              }
            }
          },
          "422": {
            "description": "Invalid request: `invalid_request`, `message_too_long`, `destination_not_allowed` or `call_not_allowed` (the content isn't transactional). The message says exactly what to fix.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "value": {
                      "error": {
                        "code": "invalid_request",
                        "message": "options[2].options has 12 items; the maximum per menu is 9 (keys 1–9). Group the rest into a submenu.",
                        "docs_url": "https://www.callhuman.es/docs/errors#invalid_request"
                      }
                    }
                  },
                  "message_too_long": {
                    "value": {
                      "error": {
                        "code": "message_too_long",
                        "message": "Your message, labels and replies are 612 characters; your plan allows 500. Remove 112 characters or upgrade.",
                        "docs_url": "https://www.callhuman.es/docs/errors#message_too_long"
                      }
                    }
                  },
                  "destination_not_allowed": {
                    "value": {
                      "error": {
                        "code": "destination_not_allowed",
                        "message": "Calls to +882 numbers are not supported. See the list of supported countries.",
                        "docs_url": "https://www.callhuman.es/docs/errors#destination_not_allowed"
                      }
                    }
                  },
                  "call_not_allowed": {
                    "value": {
                      "error": {
                        "code": "call_not_allowed",
                        "message": "This call looks like marketing or sales. CallHuman only places transactional calls (confirmations, codes, approvals, alerts). Remove the promotional part and try again.",
                        "docs_url": "https://www.callhuman.es/docs/errors#call_not_allowed"
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "`rate_limit_exceeded` (30 requests/min or 300/hour per project) or `quota_exceeded` (no answered calls left this cycle).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "rate_limit_exceeded": {
                    "value": {
                      "error": {
                        "code": "rate_limit_exceeded",
                        "message": "Too many requests: the limit is 30 per minute and 300 per hour per project. Retry in 12 seconds.",
                        "docs_url": "https://www.callhuman.es/docs/errors#rate_limit_exceeded"
                      }
                    }
                  },
                  "quota_exceeded": {
                    "value": {
                      "error": {
                        "code": "quota_exceeded",
                        "message": "You have used all 150 answered calls of this cycle. Upgrade your plan to keep calling; calls reset on December 14.",
                        "docs_url": "https://www.callhuman.es/docs/errors#quota_exceeded"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/calls/{id}": {
      "get": {
        "operationId": "getCall",
        "tags": [
          "Calls"
        ],
        "summary": "Get a call",
        "description": "Returns the current state and result of a call — the same object the webhook sends.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Call ID returned when you created the call.",
            "schema": {
              "type": "string"
            },
            "example": "call_x9f2k"
          }
        ],
        "responses": {
          "200": {
            "description": "The call.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Call"
                },
                "example": {
                  "id": "call_x9f2k",
                  "status": "answered",
                  "option_path": [
                    1
                  ],
                  "option_label": "Confirm",
                  "metadata": {
                    "booking_id": "bk_1042"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, revoked or expired API key. Create a new one in your dashboard under API keys.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "code": "invalid_api_key",
                    "message": "Missing, revoked or expired API key. Create a new one in your dashboard under API keys.",
                    "docs_url": "https://www.callhuman.es/docs/errors#invalid_api_key"
                  }
                }
              }
            }
          },
          "404": {
            "description": "No call with ID call_x9f2k in this project. Check the ID and that you use an API key of the same project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "code": "call_not_found",
                    "message": "No call with ID call_x9f2k in this project. Check the ID and that you use an API key of the same project.",
                    "docs_url": "https://www.callhuman.es/docs/errors#call_not_found"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "callResult": {
      "post": {
        "summary": "Call result",
        "description": "Sent to your `webhook_url` as `POST` with `Content-Type: application/json` when the call reaches a final status (`answered`, `not_answered` or `failed`). Verify it: compute HMAC-SHA256 of the raw request body with your project's webhook secret (dashboard → Settings), encode it as lowercase hex (no prefix) and compare it in constant time with the `CallHuman-Signature` header. Respond with a 2xx within 10 seconds; otherwise we retry up to 5 times (after 1, 5, 15, 30 and 60 minutes), so the same result may arrive more than once — deduplicate by `id`.",
        "parameters": [
          {
            "name": "CallHuman-Signature",
            "in": "header",
            "required": true,
            "description": "Lowercase hex HMAC-SHA256 of the raw body, using your project's webhook secret. No prefix, no timestamp.",
            "schema": {
              "type": "string"
            },
            "example": "5f2b1c9e0d8a7b6c5d4e3f2a1b0c9d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b2c"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Call"
              },
              "examples": {
                "answered": {
                  "summary": "Answered, option chosen",
                  "value": {
                    "id": "call_x9f2k",
                    "status": "answered",
                    "option_path": [
                      1
                    ],
                    "option_label": "Confirm",
                    "metadata": {
                      "booking_id": "bk_1042"
                    }
                  }
                },
                "submenu": {
                  "summary": "Answered, option from a submenu",
                  "value": {
                    "id": "call_c55n1",
                    "status": "answered",
                    "option_path": [
                      3,
                      2
                    ],
                    "option_label": "Deliver another day",
                    "metadata": {}
                  }
                },
                "no_choice": {
                  "summary": "Answered, nothing chosen",
                  "value": {
                    "id": "call_m21qa",
                    "status": "answered",
                    "option_path": [],
                    "option_label": null,
                    "metadata": {}
                  }
                },
                "not_answered": {
                  "summary": "Not answered after all retries",
                  "value": {
                    "id": "call_t07zz",
                    "status": "not_answered",
                    "option_path": [],
                    "option_label": null,
                    "metadata": {}
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Return any 2xx to acknowledge."
          }
        },
        "operationId": "callResult"
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Your API key, for example `Authorization: Bearer ch_live_xxxxxxxxxxxx`. Create keys in your dashboard under API keys."
      }
    },
    "schemas": {
      "Option": {
        "type": "object",
        "description": "One option offered to the person. The first option of a menu is key 1, the second key 2, and so on (up to 9). Give it a `reply` to say something back after it is chosen, or `options` to open a submenu instead. `reply` and `options` cannot be used together.",
        "required": [
          "label"
        ],
        "additionalProperties": false,
        "properties": {
          "label": {
            "type": "string",
            "minLength": 1,
            "description": "What is offered, read as “Press 1 or say <label>”. The person can press the key or say it in their own words.",
            "example": "Confirm"
          },
          "reply": {
            "type": "string",
            "minLength": 1,
            "description": "Optional. Read to the person right after they choose this option, then the call ends. If omitted, the call ends as soon as they choose.",
            "example": "Perfect, see you tonight!"
          },
          "options": {
            "type": "array",
            "minItems": 1,
            "maxItems": 9,
            "items": {
              "$ref": "#/components/schemas/Option"
            },
            "description": "Optional submenu. Choosing this option reads these options instead of ending the call. Pressing 0 or saying “back” returns to the previous menu. Maximum 3 levels in total (main menu + 2)."
          }
        }
      },
      "CreateCallRequest": {
        "type": "object",
        "required": [
          "to",
          "message"
        ],
        "additionalProperties": false,
        "description": "Send only `to` and `message` for a one-way message (for example a verification code). Add `options` to ask a question and get the answer back.",
        "properties": {
          "to": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$",
            "description": "Phone number to call, in international E.164 format (with + and country code). Must be in a supported country.",
            "example": "+34600111222"
          },
          "message": {
            "type": "string",
            "minLength": 1,
            "description": "Text read out loud when the person answers. Your plan limits the total length of `message` plus every `label` and `reply`.",
            "example": "Hi! This is La Plaza about your table for 4 tonight at 8:30 pm."
          },
          "options": {
            "type": "array",
            "minItems": 1,
            "maxItems": 9,
            "items": {
              "$ref": "#/components/schemas/Option"
            },
            "description": "Options the person can choose, by keypress or by voice. Up to 9 per menu. Omit it for a one-way message: the text is read once and the call ends (one attempt, no retries)."
          },
          "language": {
            "type": "string",
            "default": "en",
            "description": "Language the message and menus are read in (ISO 639-1 code). Defaults to `en`. Common: en, es, fr, de, it, pt. An unsupported code returns `invalid_request` listing the supported ones.",
            "examples": [
              "en",
              "es",
              "fr",
              "de",
              "it",
              "pt"
            ]
          },
          "webhook_url": {
            "type": "string",
            "format": "uri",
            "description": "HTTPS URL (max 2,048 characters) that receives the result as a JSON POST (see the `callResult` webhook). Optional: you can also poll `GET /calls/{id}`.",
            "example": "https://laplaza.example/hooks/callhuman",
            "pattern": "^https://",
            "maxLength": 2048
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true,
            "description": "Any JSON object you want back (max 4 KB serialized), returned unchanged in the result. Typically your own record ID.",
            "example": {
              "booking_id": "bk_1042"
            }
          }
        }
      },
      "CallCreated": {
        "type": "object",
        "required": [
          "id",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Call ID. Use it with `GET /calls/{id}`.",
            "example": "call_x9f2k"
          },
          "status": {
            "type": "string",
            "const": "queued",
            "description": "Always `queued` when created.",
            "example": "queued"
          }
        }
      },
      "Call": {
        "type": "object",
        "required": [
          "id",
          "status",
          "option_path",
          "option_label",
          "metadata"
        ],
        "description": "A call and its result. The webhook body and `GET /calls/{id}` return exactly this object.",
        "properties": {
          "id": {
            "type": "string",
            "description": "Call ID.",
            "example": "call_x9f2k"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "in_progress",
              "answered",
              "not_answered",
              "failed"
            ],
            "description": "`queued`: waiting or between retries. `in_progress`: ringing or on the call. `answered`: the person picked up (counts towards your plan). `not_answered`: no answer, busy or voicemail after all retries (free). `failed`: invalid number or technical error (free).",
            "example": "answered"
          },
          "option_path": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9
            },
            "description": "Keys leading to the chosen option: `[2]` is option 2 of the main menu; `[3, 1]` is option 1 of the submenu under option 3. Empty if nothing was chosen.",
            "example": [
              1
            ]
          },
          "option_label": {
            "type": [
              "string",
              "null"
            ],
            "description": "Label of the chosen option, or `null` if nothing was chosen.",
            "example": "Confirm"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true,
            "description": "The `metadata` you sent, unchanged.",
            "example": {
              "booking_id": "bk_1042"
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "docs_url"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid_api_key",
                  "subscription_required",
                  "invalid_request",
                  "message_too_long",
                  "destination_not_allowed",
                  "rate_limit_exceeded",
                  "quota_exceeded",
                  "call_not_found",
                  "project_suspended",
                  "call_not_allowed"
                ],
                "description": "Stable, machine-readable error code.",
                "example": "message_too_long"
              },
              "message": {
                "type": "string",
                "description": "Human-readable explanation of what is wrong and how to fix it, in English.",
                "example": "Your message, labels and replies are 612 characters; your plan allows 500. Remove 112 characters or upgrade."
              },
              "docs_url": {
                "type": "string",
                "format": "uri",
                "description": "Link to this error in the docs.",
                "example": "https://www.callhuman.es/docs/errors#message_too_long"
              }
            }
          }
        }
      }
    }
  }
}