{
  "openapi": "3.1.0",
  "info": {
    "title": "aiyourbusiness API",
    "version": "1.0.0",
    "description": "Send WhatsApp messages from your own systems. Messages sent through the API appear in the same conversation\nas the AI and your team (as `api` messages).\n\n**Authentication**: `Authorization: Bearer ga_live_...` (create keys in Settings -> API keys; a key is shown\nonce). HTTPS only. Requires the Professional plan.\n\n**Scopes**: `whatsapp:send`, `whatsapp:read`, `messenger:send`, `instagram:send`, `*`. A key may also be restricted to some agents.\n\n**Errors** use one envelope: `{ error: { type, code, message, param? }, correlation_id }`; the correlation id\nis also sent as `X-Correlation-Id`.\n\n**Rate limits**: 60 requests per minute per key (token bucket). Every response carries `X-RateLimit-Limit`,\n`X-RateLimit-Remaining` and `X-RateLimit-Reset`; a 429 carries `Retry-After`.\n\n**Idempotency**: send `Idempotency-Key` (1-255 characters) on POST requests. A retry with the same key and\nbody within 24 hours returns the first response (`Idempotent-Replayed: true`); a different body is a 422, a\nretry while the first request still runs is a 409."
  },
  "servers": [
    {
      "url": "/api/v1",
      "description": "This deployment (relative to the site that serves this document)"
    }
  ],
  "security": [{ "bearerAuth": [] }],
  "tags": [
    {
      "name": "WhatsApp",
      "description": "Send messages and templates on a connected WhatsApp number."
    },
    { "name": "Messages", "description": "Delivery status of messages." },
    { "name": "Meta", "description": "Health and the API description." },
    { "name": "Reserved", "description": "Channels that will be added later." }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": ["Meta"],
        "summary": "Check an API key",
        "description": "Validates the key and the plan; any scope works.",
        "operationId": "getHealth",
        "responses": {
          "200": {
            "description": "The key works.",
            "headers": {
              "X-RateLimit-Limit": { "$ref": "#/components/headers/X-RateLimit-Limit" },
              "X-RateLimit-Remaining": { "$ref": "#/components/headers/X-RateLimit-Remaining" },
              "X-RateLimit-Reset": { "$ref": "#/components/headers/X-RateLimit-Reset" },
              "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" }
            },
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/Health" } }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/TooManyRequests" },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    },
    "/whatsapp/messages": {
      "post": {
        "tags": ["WhatsApp"],
        "summary": "Send a text message",
        "description": "Sends free-form text inside the 24-hour customer service window (the recipient wrote to this number in the last 24 hours). Outside it the answer is `409 window_closed`; send a template instead. Requires `whatsapp:send`.",
        "operationId": "sendWhatsAppText",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/SendTextRequest" } }
          }
        },
        "responses": {
          "202": {
            "description": "Queued for delivery.",
            "headers": {
              "X-RateLimit-Limit": { "$ref": "#/components/headers/X-RateLimit-Limit" },
              "X-RateLimit-Remaining": { "$ref": "#/components/headers/X-RateLimit-Remaining" },
              "X-RateLimit-Reset": { "$ref": "#/components/headers/X-RateLimit-Reset" },
              "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" }
            },
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/QueuedMessage" } }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/Conflict" },
          "422": { "$ref": "#/components/responses/Unprocessable" },
          "429": { "$ref": "#/components/responses/TooManyRequests" },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    },
    "/whatsapp/templates/send": {
      "post": {
        "tags": ["WhatsApp"],
        "summary": "Send a template message",
        "description": "Sends an approved template at any time. The template is checked against the approved templates of the number's WhatsApp Business Account (`422 template_not_approved`) and the parameter counts against its body, header and URL buttons (`422 template_param_mismatch`). Requires `whatsapp:send`.",
        "operationId": "sendWhatsAppTemplate",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/SendTemplateRequest" } }
          }
        },
        "responses": {
          "202": {
            "description": "Queued for delivery.",
            "headers": {
              "X-RateLimit-Limit": { "$ref": "#/components/headers/X-RateLimit-Limit" },
              "X-RateLimit-Remaining": { "$ref": "#/components/headers/X-RateLimit-Remaining" },
              "X-RateLimit-Reset": { "$ref": "#/components/headers/X-RateLimit-Reset" },
              "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" }
            },
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/QueuedMessage" } }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/Conflict" },
          "422": { "$ref": "#/components/responses/Unprocessable" },
          "429": { "$ref": "#/components/responses/TooManyRequests" },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    },
    "/whatsapp/templates": {
      "get": {
        "tags": ["WhatsApp"],
        "summary": "List approved templates",
        "description": "Approved templates of a number. Give `connection_id` or `from_phone_number_id`. Requires `whatsapp:read`.",
        "operationId": "listWhatsAppTemplates",
        "parameters": [
          {
            "name": "connection_id",
            "in": "query",
            "required": false,
            "description": "The aiyourbusiness WhatsApp connection id. Give this or `from_phone_number_id`.",
            "schema": {
              "type": "string",
              "format": "uuid",
              "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
            }
          },
          {
            "name": "from_phone_number_id",
            "in": "query",
            "required": false,
            "description": "Meta's phone_number_id of the sending number. Give this or `connection_id`.",
            "schema": { "type": "string", "pattern": "^\\d{1,64}$" }
          }
        ],
        "responses": {
          "200": {
            "description": "Approved templates.",
            "headers": {
              "X-RateLimit-Limit": { "$ref": "#/components/headers/X-RateLimit-Limit" },
              "X-RateLimit-Remaining": { "$ref": "#/components/headers/X-RateLimit-Remaining" },
              "X-RateLimit-Reset": { "$ref": "#/components/headers/X-RateLimit-Reset" },
              "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" }
            },
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/TemplateList" } }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/Conflict" },
          "429": { "$ref": "#/components/responses/TooManyRequests" },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    },
    "/messages/{id}": {
      "get": {
        "tags": ["Messages"],
        "summary": "Get a message",
        "description": "Delivery status, timestamps and error of a message. Requires `whatsapp:read`.",
        "operationId": "getMessage",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "responses": {
          "200": {
            "description": "The message.",
            "headers": {
              "X-RateLimit-Limit": { "$ref": "#/components/headers/X-RateLimit-Limit" },
              "X-RateLimit-Remaining": { "$ref": "#/components/headers/X-RateLimit-Remaining" },
              "X-RateLimit-Reset": { "$ref": "#/components/headers/X-RateLimit-Reset" },
              "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" }
            },
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/Message" } }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/TooManyRequests" },
          "500": { "$ref": "#/components/responses/ServerError" }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "tags": ["Meta"],
        "summary": "This document",
        "operationId": "getOpenApi",
        "security": [],
        "responses": {
          "200": { "description": "OpenAPI 3.1 document.", "content": { "application/json": {} } }
        }
      }
    },
    "/messenger/messages": {
      "post": {
        "tags": ["Reserved"],
        "summary": "Messenger endpoints (not available yet)",
        "operationId": "messengerNotImplemented",
        "security": [],
        "responses": { "501": { "$ref": "#/components/responses/NotImplemented" } }
      }
    },
    "/instagram/messages": {
      "post": {
        "tags": ["Reserved"],
        "summary": "Instagram endpoints (not available yet)",
        "operationId": "instagramNotImplemented",
        "security": [],
        "responses": { "501": { "$ref": "#/components/responses/NotImplemented" } }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "ga_live_<22>_<10>",
        "description": "An API key from Settings -> API keys."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "1-255 characters. Same key + same request within 24 hours replays the first response.",
        "schema": { "type": "string", "minLength": 1, "maxLength": 255 }
      }
    },
    "headers": {
      "X-RateLimit-Limit": {
        "description": "Requests allowed per minute.",
        "schema": { "type": "integer" }
      },
      "X-RateLimit-Remaining": {
        "description": "Requests left right now.",
        "schema": { "type": "integer" }
      },
      "X-RateLimit-Reset": {
        "description": "Unix time (seconds) at which the limit is fully restored.",
        "schema": { "type": "integer" }
      },
      "X-Correlation-Id": {
        "description": "Identifies the request; quote it when contacting support.",
        "schema": { "type": "string" }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "The request is not valid (`invalid_request`, `invalid_idempotency_key`, `payload_too_large`).",
        "headers": { "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" } },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "examples": {
              "invalid_request": {
                "value": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "invalid_request",
                    "message": "to: phone must be E.164 (+201234567890)",
                    "param": "to"
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, malformed, unknown, expired or revoked API key.",
        "headers": { "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" } },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "examples": {
              "invalid_api_key": {
                "value": {
                  "error": {
                    "type": "authentication_error",
                    "code": "invalid_api_key",
                    "message": "The API key is invalid, expired or revoked."
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              }
            }
          }
        }
      },
      "Forbidden": {
        "description": "`insufficient_scope` (with `required_scope`), `agent_not_authorized`, `plan_required` or `https_required`.",
        "headers": { "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" } },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "examples": {
              "insufficient_scope": {
                "value": {
                  "error": {
                    "type": "permission_error",
                    "code": "insufficient_scope",
                    "message": "This API key does not have the whatsapp:send scope.",
                    "required_scope": "whatsapp:send"
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              },
              "agent_not_authorized": {
                "value": {
                  "error": {
                    "type": "permission_error",
                    "code": "agent_not_authorized",
                    "message": "This API key is restricted to other agents."
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              },
              "plan_required": {
                "value": {
                  "error": {
                    "type": "permission_error",
                    "code": "plan_required",
                    "message": "The public API is not included in this workspace's plan.",
                    "required_feature": "public_api"
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "`connection_not_found`, `message_not_found`, `reply_to_message_not_found` or `route_not_found`.",
        "headers": { "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" } },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "examples": {
              "connection_not_found": {
                "value": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "connection_not_found",
                    "message": "No such connection.",
                    "param": "connection_id"
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              }
            }
          }
        }
      },
      "Conflict": {
        "description": "`window_closed` (with `free_form_until`), `connection_unavailable`, `recipient_unavailable` or `idempotency_in_progress`.",
        "headers": { "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" } },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "examples": {
              "window_closed": {
                "value": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "window_closed",
                    "message": "The 24-hour customer service window with this recipient is closed. Send an approved template instead.",
                    "param": "to",
                    "free_form_until": "2026-10-11T09:30:00Z"
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              },
              "idempotency_in_progress": {
                "value": {
                  "error": {
                    "type": "idempotency_error",
                    "code": "idempotency_in_progress",
                    "message": "A request with this Idempotency-Key is still being processed. Retry shortly.",
                    "param": "Idempotency-Key"
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              }
            }
          }
        }
      },
      "Unprocessable": {
        "description": "`template_not_approved`, `template_param_mismatch` or `idempotency_key_mismatch`.",
        "headers": { "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" } },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "examples": {
              "template_param_mismatch": {
                "value": {
                  "error": {
                    "type": "invalid_request_error",
                    "code": "template_param_mismatch",
                    "message": "The template body expects 2 parameter(s), got 1.",
                    "param": "template.components"
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              },
              "idempotency_key_mismatch": {
                "value": {
                  "error": {
                    "type": "idempotency_error",
                    "code": "idempotency_key_mismatch",
                    "message": "This Idempotency-Key was already used with a different request.",
                    "param": "Idempotency-Key"
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              }
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "More than the key's limit (60 requests per minute by default). Honour `Retry-After`.",
        "headers": { "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" } },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "examples": {
              "rate_limited": {
                "value": {
                  "error": {
                    "type": "rate_limit_error",
                    "code": "rate_limited",
                    "message": "Too many requests. Please retry later."
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              }
            }
          }
        }
      },
      "ServerError": {
        "description": "`internal_error`: retry with the same Idempotency-Key.",
        "headers": { "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" } },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "examples": {
              "internal_error": {
                "value": {
                  "error": {
                    "type": "api_error",
                    "code": "internal_error",
                    "message": "Something went wrong on our side. Please retry."
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              }
            }
          }
        }
      },
      "NotImplemented": {
        "description": "`not_implemented`: the channel is not available in the API yet.",
        "headers": { "X-Correlation-Id": { "$ref": "#/components/headers/X-Correlation-Id" } },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "examples": {
              "not_implemented": {
                "value": {
                  "error": {
                    "type": "api_error",
                    "code": "not_implemented",
                    "message": "This channel is not available in the API yet."
                  },
                  "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "SendTextRequest": {
        "type": "object",
        "properties": {
          "connection_id": {
            "description": "The aiyourbusiness WhatsApp connection id. Give this or `from_phone_number_id`.",
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "from_phone_number_id": {
            "description": "Meta's phone_number_id of the sending number. Give this or `connection_id`.",
            "type": "string",
            "pattern": "^\\d{1,64}$"
          },
          "to": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$",
            "description": "Recipient in E.164 format.",
            "examples": ["+201001234567"]
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4096,
            "description": "Plain text, up to 4096 characters."
          },
          "reply_to": {
            "description": "Id of a message in the same conversation to quote.",
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "metadata": {
            "type": "object",
            "propertyNames": { "type": "string", "pattern": "^[A-Za-z0-9_.-]{1,40}$" },
            "additionalProperties": { "type": "string", "maxLength": 500 },
            "description": "Up to 20 string values (keys 1-40 characters, values up to 500) stored with the message."
          }
        },
        "required": ["to", "text"],
        "additionalProperties": false,
        "examples": [
          {
            "from_phone_number_id": "123456789012345",
            "to": "+201001234567",
            "text": "Your order #1042 has shipped.",
            "metadata": { "order_id": "1042" }
          }
        ]
      },
      "SendTemplateRequest": {
        "type": "object",
        "properties": {
          "connection_id": {
            "description": "The aiyourbusiness WhatsApp connection id. Give this or `from_phone_number_id`.",
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "from_phone_number_id": {
            "description": "Meta's phone_number_id of the sending number. Give this or `connection_id`.",
            "type": "string",
            "pattern": "^\\d{1,64}$"
          },
          "to": {
            "type": "string",
            "pattern": "^\\+[1-9]\\d{6,14}$",
            "description": "Recipient in E.164 format.",
            "examples": ["+201001234567"]
          },
          "template": {
            "type": "object",
            "properties": {
              "name": { "type": "string", "pattern": "^[a-z0-9_]{1,512}$" },
              "language": { "type": "string", "pattern": "^[a-z]{2,3}(_[A-Z]{2})?$" },
              "components": {
                "default": [],
                "maxItems": 20,
                "type": "array",
                "items": { "$ref": "#/components/schemas/TemplateComponent" }
              }
            },
            "required": ["name", "language"],
            "additionalProperties": false
          },
          "metadata": {
            "type": "object",
            "propertyNames": { "type": "string", "pattern": "^[A-Za-z0-9_.-]{1,40}$" },
            "additionalProperties": { "type": "string", "maxLength": 500 },
            "description": "Up to 20 string values (keys 1-40 characters, values up to 500) stored with the message."
          }
        },
        "required": ["to", "template"],
        "additionalProperties": false,
        "examples": [
          {
            "connection_id": "6f1c2b9e-1d2a-4c55-9b0e-8a4f2d7c1e10",
            "to": "+201001234567",
            "template": {
              "name": "order_shipped",
              "language": "en_US",
              "components": [{ "type": "body", "parameters": [{ "type": "text", "text": "1042" }] }]
            }
          }
        ]
      },
      "TemplateParameter": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "text",
              "currency",
              "date_time",
              "image",
              "video",
              "document",
              "location",
              "payload",
              "coupon_code",
              "action"
            ]
          },
          "text": { "type": "string", "maxLength": 1024 },
          "parameter_name": { "type": "string", "maxLength": 100, "pattern": "^[a-z][a-z0-9_]*$" }
        },
        "required": ["type"],
        "additionalProperties": {},
        "description": "A parameter in WhatsApp Cloud API format (other fields such as `image` or `currency` pass through)."
      },
      "TemplateComponent": {
        "type": "object",
        "properties": {
          "type": { "type": "string", "enum": ["header", "body", "button"] },
          "sub_type": {
            "type": "string",
            "enum": ["quick_reply", "url", "copy_code", "flow", "catalog"]
          },
          "index": {
            "anyOf": [
              { "type": "integer", "minimum": 0, "maximum": 9 },
              { "type": "string", "pattern": "^\\d$" }
            ]
          },
          "parameters": {
            "default": [],
            "maxItems": 100,
            "type": "array",
            "items": { "$ref": "#/components/schemas/TemplateParameter" }
          }
        },
        "required": ["type"],
        "additionalProperties": false
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "invalid_request_error",
                  "authentication_error",
                  "permission_error",
                  "rate_limit_error",
                  "idempotency_error",
                  "api_error"
                ]
              },
              "code": { "type": "string", "examples": ["insufficient_scope"] },
              "message": { "type": "string" },
              "param": { "type": "string" }
            },
            "required": ["type", "code", "message"],
            "additionalProperties": {}
          },
          "correlation_id": {
            "type": "string",
            "description": "Also sent as the X-Correlation-Id header."
          }
        },
        "required": ["error", "correlation_id"],
        "examples": [
          {
            "error": {
              "type": "permission_error",
              "code": "insufficient_scope",
              "message": "This API key does not have the whatsapp:send scope.",
              "required_scope": "whatsapp:send"
            },
            "correlation_id": "0b7c8a0e-3f4d-4a43-a1d2-2e8e5a9c6b71"
          }
        ]
      },
      "QueuedMessage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "object": { "type": "string", "const": "message" },
          "conversation_id": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "status": { "type": "string", "const": "queued" },
          "metadata": {
            "type": "object",
            "propertyNames": { "type": "string" },
            "additionalProperties": { "type": "string" }
          }
        },
        "required": ["id", "object", "conversation_id", "status"],
        "examples": [
          {
            "id": "2b0d7c4e-8a8f-4a8e-9e0f-63b1f1f0c001",
            "object": "message",
            "conversation_id": "9c1e5d2a-7b3f-4f0e-8d6a-1a2b3c4d5e6f",
            "status": "queued"
          }
        ]
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "object": { "type": "string", "const": "message" },
          "conversation_id": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "channel": {
            "type": "string",
            "enum": ["whatsapp", "messenger", "instagram", "website", "landing", "test"]
          },
          "direction": { "type": "string", "enum": ["inbound", "outbound"] },
          "sender_type": {
            "type": "string",
            "enum": ["customer", "ai", "human", "external_human", "api", "broadcast", "system"]
          },
          "content_type": { "type": "string" },
          "status": {
            "anyOf": [
              {
                "type": "string",
                "enum": ["queued", "sending", "sent", "delivered", "read", "played", "failed"]
              },
              { "type": "null" }
            ]
          },
          "sent_by_this_key": { "type": "boolean" },
          "created_at": { "type": "string" },
          "sent_at": { "type": ["string", "null"] },
          "delivered_at": { "type": ["string", "null"] },
          "read_at": { "type": ["string", "null"] },
          "failed_at": { "type": ["string", "null"] },
          "error": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "code": { "type": "string" },
                  "title": { "type": ["string", "null"] },
                  "detail": { "type": ["string", "null"] }
                },
                "required": ["code", "title", "detail"]
              },
              { "type": "null" }
            ]
          },
          "metadata": {
            "type": "object",
            "propertyNames": { "type": "string" },
            "additionalProperties": { "type": "string" }
          }
        },
        "required": [
          "id",
          "object",
          "conversation_id",
          "channel",
          "direction",
          "sender_type",
          "content_type",
          "status",
          "sent_by_this_key",
          "created_at",
          "sent_at",
          "delivered_at",
          "read_at",
          "failed_at",
          "error"
        ]
      },
      "Template": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "language": { "type": "string" },
          "category": { "type": "string" },
          "status": { "type": "string", "const": "approved" },
          "parameter_format": { "type": "string", "enum": ["positional", "named"] },
          "components": {
            "type": "array",
            "items": {},
            "description": "Meta's template components as approved."
          }
        },
        "required": ["name", "language", "category", "status", "parameter_format", "components"]
      },
      "TemplateList": {
        "type": "object",
        "properties": {
          "object": { "type": "string", "const": "list" },
          "data": { "type": "array", "items": { "$ref": "#/components/schemas/Template" } }
        },
        "required": ["object", "data"]
      },
      "Health": {
        "type": "object",
        "properties": {
          "status": { "type": "string", "const": "ok" },
          "livemode": { "type": "boolean" },
          "time": { "type": "string" },
          "key": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid",
                "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
              },
              "prefix": { "type": "string" },
              "scopes": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "whatsapp:send",
                    "whatsapp:read",
                    "messenger:send",
                    "instagram:send",
                    "*"
                  ]
                }
              },
              "agent_ids": {
                "anyOf": [
                  {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid",
                      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                    }
                  },
                  { "type": "null" }
                ]
              }
            },
            "required": ["id", "prefix", "scopes", "agent_ids"]
          }
        },
        "required": ["status", "livemode", "time", "key"]
      }
    }
  }
}
