{
  "openapi": "3.1.0",
  "info": {
    "title": "Bonga Messaging API",
    "version": "2.0",
    "description": "Discover a sender, choose the supported content type, and track the message. This is the v2 preview contract: provider delivery is not enabled by this preview. An empty discovery list means no sender matched the selected channel and filters."
  },
  "servers": [
    {
      "url": "https://api.bonga.africa"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "Sender discovery"
    },
    {
      "name": "Messages"
    },
    {
      "name": "Email"
    }
  ],
  "paths": {
    "/api/v2/email/sending-limits": {
      "get": {
        "tags": [
          "Email"
        ],
        "operationId": "getEmailSendingLimits",
        "summary": "Read email sending limits",
        "description": "Requires `email:limits:read`. Reports the effective billing workspace's current UTC-day email plan cap and counter. A null cap means no plan daily cap; usage is not reported for uncapped plans. This does not grant sending access or report wallet balances, provider pacing, or sender reputation.",
        "responses": {
          "200": {
            "description": "Current email plan limits.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "daily_cap": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        },
                        "used": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        },
                        "remaining": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        },
                        "resets_at": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time"
                        }
                      },
                      "required": [
                        "daily_cap",
                        "used",
                        "remaining",
                        "resets_at"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                },
                "example": {
                  "success": true,
                  "message": "Email sending limits",
                  "data": {
                    "daily_cap": 500,
                    "used": 25,
                    "remaining": 475,
                    "resets_at": "2026-12-01T00:00:00Z"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The API key lacks the required permission. Error codes: PERMISSION_DENIED.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "The service is temporarily unavailable. Error codes: EMAIL_LIMITS_UNAVAILABLE.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v2/senders": {
      "get": {
        "tags": [
          "Sender discovery"
        ],
        "operationId": "listSenders",
        "summary": "List senders",
        "description": "Requires `messages:read`. Match `connection_id` to the connection for a device or account. Configured identities marked `not_qualified` cannot submit preview messages.",
        "parameters": [
          {
            "name": "channel",
            "in": "query",
            "description": "Filter by channel. Omission selects SMS. Disabled channels are refused.",
            "schema": {
              "type": "string",
              "enum": [
                "sms",
                "whatsapp",
                "email"
              ],
              "default": "sms"
            }
          },
          {
            "name": "connection_id",
            "in": "query",
            "description": "Return only the connection with this ID and, where applicable, its senders.",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          },
          {
            "name": "type",
            "in": "query",
            "description": "Exact sender type from discovery, such as `sim`. Does not filter the connections array.",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Scoped senders and connections.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "senders": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Sender"
                          }
                        },
                        "connections": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Connection"
                          }
                        }
                      },
                      "required": [
                        "senders",
                        "connections"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                },
                "example": {
                  "success": true,
                  "message": "Senders discovered",
                  "data": {
                    "senders": [
                      {
                        "id": "snd_cfgsample1",
                        "channel": "sms",
                        "type": "sim",
                        "label": "SIM 1",
                        "slot": 1,
                        "connection_id": "con_cfg_example",
                        "ready": false,
                        "readiness_reason": "not_qualified",
                        "content_types": [],
                        "receive": false,
                        "receipts": false
                      },
                      {
                        "id": "snd_cfgsample2",
                        "channel": "sms",
                        "type": "sim",
                        "label": "SIM 2",
                        "slot": 2,
                        "connection_id": "con_cfg_example",
                        "ready": false,
                        "readiness_reason": "not_qualified",
                        "content_types": [],
                        "receive": false,
                        "receipts": false
                      }
                    ],
                    "connections": [
                      {
                        "id": "con_cfg_example",
                        "channel": "sms",
                        "kind": "android_sim",
                        "label": "Dispatch phone",
                        "ready": false,
                        "readiness_reason": "not_qualified"
                      }
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, destination, content, or idempotency key. Error codes: INVALID_DISCOVERY_FILTER.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The API key lacks the required permission. Error codes: PERMISSION_DENIED.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "422": {
            "description": "The requested channel or content is unavailable for this sender. Error codes: CHANNEL_UNQUALIFIED.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "The service is temporarily unavailable. Error codes: DISCOVERY_UNAVAILABLE.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v2/connections": {
      "get": {
        "tags": [
          "Sender discovery"
        ],
        "operationId": "listConnections",
        "summary": "List connections",
        "description": "Requires `messages:read`. Connections describe devices and accounts without exposing credentials.",
        "parameters": [
          {
            "name": "channel",
            "in": "query",
            "description": "Filter by channel. Omission selects SMS. Disabled channels are refused.",
            "schema": {
              "type": "string",
              "enum": [
                "sms",
                "whatsapp",
                "email"
              ],
              "default": "sms"
            }
          },
          {
            "name": "connection_id",
            "in": "query",
            "description": "Return only the connection with this ID and, where applicable, its senders.",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Scoped connections.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Connection"
                      }
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                },
                "example": {
                  "success": true,
                  "message": "Connections discovered",
                  "data": [
                    {
                      "id": "con_cfg_example",
                      "channel": "sms",
                      "kind": "android_sim",
                      "label": "Dispatch phone",
                      "ready": false,
                      "readiness_reason": "not_qualified"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, destination, content, or idempotency key. Error codes: INVALID_DISCOVERY_FILTER.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The API key lacks the required permission. Error codes: PERMISSION_DENIED.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "422": {
            "description": "The requested channel or content is unavailable for this sender. Error codes: CHANNEL_UNQUALIFIED.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "The service is temporarily unavailable. Error codes: DISCOVERY_UNAVAILABLE.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v2/messages": {
      "post": {
        "tags": [
          "Messages"
        ],
        "operationId": "submitMessage",
        "summary": "Submit one message (preview)",
        "description": "Requires `messages:send`. Replace the example `from` with a ready sender ID from discovery. Replay the same key and payload to return the existing message. The preview also refuses identical normalized payloads under different keys in the same workspace. Availability is restricted to configured preview routes. The JSON body is limited to 32 KiB. A queued message has not been sent.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "8–200 visible ASCII characters. Keep the same key and payload on retries.",
            "schema": {
              "type": "string",
              "pattern": "^[!-~]{8,200}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "channel": {
                        "const": "sms"
                      },
                      "from": {
                        "type": "string",
                        "pattern": "^snd_[a-z0-9]{8,40}$",
                        "description": "Opaque ID of a ready sender returned by discovery."
                      },
                      "to": {
                        "type": "string",
                        "pattern": "^\\+[1-9][0-9]{6,14}$",
                        "description": "One recipient: an email address for email, or an E.164 number for SMS and WhatsApp."
                      },
                      "content": {
                        "type": "object",
                        "properties": {
                          "type": {
                            "const": "text"
                          },
                          "text": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 1600
                          }
                        },
                        "required": [
                          "type",
                          "text"
                        ],
                        "additionalProperties": false,
                        "description": "Use a content type listed by the selected sender."
                      },
                      "purpose": {
                        "enum": [
                          "transactional",
                          "marketing",
                          "support",
                          "authentication"
                        ],
                        "default": "transactional",
                        "description": "Purpose used to apply sender and content policy."
                      }
                    },
                    "required": [
                      "channel",
                      "from",
                      "to",
                      "content"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "channel": {
                        "const": "whatsapp"
                      },
                      "from": {
                        "type": "string",
                        "pattern": "^snd_[a-z0-9]{8,40}$",
                        "description": "Opaque ID of a ready sender returned by discovery."
                      },
                      "to": {
                        "type": "string",
                        "pattern": "^\\+[1-9][0-9]{6,14}$",
                        "description": "One recipient: an email address for email, or an E.164 number for SMS and WhatsApp."
                      },
                      "content": {
                        "type": "object",
                        "properties": {
                          "type": {
                            "const": "text"
                          },
                          "text": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 1600
                          }
                        },
                        "required": [
                          "type",
                          "text"
                        ],
                        "additionalProperties": false,
                        "description": "Use a content type listed by the selected sender."
                      },
                      "purpose": {
                        "enum": [
                          "transactional",
                          "marketing",
                          "support",
                          "authentication"
                        ],
                        "default": "transactional",
                        "description": "Purpose used to apply sender and content policy."
                      }
                    },
                    "required": [
                      "channel",
                      "from",
                      "to",
                      "content"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "channel": {
                        "const": "whatsapp"
                      },
                      "from": {
                        "type": "string",
                        "pattern": "^snd_[a-z0-9]{8,40}$",
                        "description": "Opaque ID of a ready sender returned by discovery."
                      },
                      "to": {
                        "type": "string",
                        "pattern": "^\\+[1-9][0-9]{6,14}$",
                        "description": "One recipient: an email address for email, or an E.164 number for SMS and WhatsApp."
                      },
                      "content": {
                        "type": "object",
                        "properties": {
                          "type": {
                            "const": "template"
                          },
                          "template_id": {
                            "type": "string",
                            "pattern": "^[a-z0-9_.-]{3,64}$"
                          },
                          "parameters": {
                            "type": "array",
                            "items": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 1600
                            },
                            "maxItems": 10
                          }
                        },
                        "required": [
                          "type",
                          "template_id"
                        ],
                        "additionalProperties": false,
                        "description": "Use a content type listed by the selected sender."
                      },
                      "purpose": {
                        "enum": [
                          "transactional",
                          "marketing",
                          "support",
                          "authentication"
                        ],
                        "default": "transactional",
                        "description": "Purpose used to apply sender and content policy."
                      }
                    },
                    "required": [
                      "channel",
                      "from",
                      "to",
                      "content"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "channel": {
                        "const": "email"
                      },
                      "from": {
                        "type": "string",
                        "pattern": "^snd_[a-z0-9]{8,40}$",
                        "description": "Opaque ID of a ready sender returned by discovery."
                      },
                      "to": {
                        "type": "string",
                        "format": "email",
                        "maxLength": 254,
                        "description": "One recipient: an email address for email, or an E.164 number for SMS and WhatsApp."
                      },
                      "content": {
                        "type": "object",
                        "properties": {
                          "type": {
                            "const": "email"
                          },
                          "subject": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 200
                          },
                          "text": {
                            "type": "string",
                            "maxLength": 20000
                          },
                          "html": {
                            "type": "string",
                            "maxLength": 20000
                          }
                        },
                        "required": [
                          "type",
                          "subject"
                        ],
                        "additionalProperties": false,
                        "anyOf": [
                          {
                            "required": [
                              "text"
                            ],
                            "properties": {
                              "text": {
                                "pattern": "\\S"
                              }
                            }
                          },
                          {
                            "required": [
                              "html"
                            ],
                            "properties": {
                              "html": {
                                "pattern": "\\S"
                              }
                            }
                          }
                        ],
                        "description": "Use a content type listed by the selected sender."
                      },
                      "purpose": {
                        "enum": [
                          "transactional",
                          "marketing",
                          "support",
                          "authentication"
                        ],
                        "default": "transactional",
                        "description": "Purpose used to apply sender and content policy."
                      }
                    },
                    "required": [
                      "channel",
                      "from",
                      "to",
                      "content"
                    ],
                    "additionalProperties": false
                  }
                ]
              },
              "examples": {
                "sms": {
                  "value": {
                    "channel": "sms",
                    "from": "snd_example01",
                    "to": "+254712345678",
                    "content": {
                      "type": "text",
                      "text": "Your order is ready."
                    }
                  }
                },
                "linkedWhatsApp": {
                  "value": {
                    "channel": "whatsapp",
                    "from": "snd_example02",
                    "to": "+254712345678",
                    "content": {
                      "type": "text",
                      "text": "Your order is ready."
                    }
                  }
                },
                "whatsAppTemplate": {
                  "value": {
                    "channel": "whatsapp",
                    "from": "snd_example03",
                    "to": "+254712345678",
                    "content": {
                      "type": "template",
                      "template_id": "order_ready"
                    }
                  }
                },
                "email": {
                  "value": {
                    "channel": "email",
                    "from": "snd_example04",
                    "to": "customer@example.com",
                    "content": {
                      "type": "email",
                      "subject": "Order ready",
                      "text": "Your order is ready.",
                      "html": "<p>Your order is <strong>ready</strong>.</p>"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Durable acceptance in the preview, with no guarantee of provider handoff.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "$ref": "#/components/schemas/Message"
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                },
                "example": {
                  "success": true,
                  "message": "Message queued",
                  "data": {
                    "id": "msg_0123456789abcdef",
                    "channel": "sms",
                    "sender_id": "snd_example01",
                    "destination": "+254712345678",
                    "status": "queued",
                    "revision": 1,
                    "purpose": "transactional",
                    "created_at": "2026-11-29T09:30:00Z",
                    "updated_at": "2026-11-29T09:30:00Z"
                  }
                }
              }
            },
            "headers": {
              "Location": {
                "description": "Path for reading this message.",
                "schema": {
                  "type": "string"
                }
              },
              "Idempotent-Replay": {
                "description": "Present with value true on replay.",
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, destination, content, or idempotency key. Error codes: INVALID_IDEMPOTENCY_KEY, INVALID_REQUEST, INVALID_CHANNEL, INVALID_SENDER, INVALID_DESTINATION, INVALID_CONTENT, INVALID_PURPOSE.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The API key lacks the required permission. Error codes: PERMISSION_DENIED.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "The resource is unknown or inaccessible. Error codes: SENDER_NOT_FOUND.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The sender is not ready, or the preview rejected an idempotency conflict. Error codes: SENDER_NOT_READY, IDEMPOTENCY_CONFLICT.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "422": {
            "description": "The requested channel or content is unavailable for this sender. Error codes: CHANNEL_UNQUALIFIED, CONTENT_UNQUALIFIED, TEMPLATE_UNQUALIFIED, INTENT_REFUSED.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "The service is temporarily unavailable. Error codes: SENDER_UNAVAILABLE, CAPABILITY_UNAVAILABLE, ACCEPTANCE_UNAVAILABLE.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v2/messages/{id}": {
      "get": {
        "tags": [
          "Messages"
        ],
        "operationId": "getMessage",
        "summary": "Track a message",
        "description": "Requires `messages:read`. Use the path returned in `Location`; unknown and inaccessible messages both return 404.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Message ID from the submission response or its Location header.",
            "schema": {
              "type": "string",
              "pattern": "^msg_[a-f0-9]{16,64}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current evidence-based status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "$ref": "#/components/schemas/Message"
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                },
                "example": {
                  "success": true,
                  "message": "Message status",
                  "data": {
                    "id": "msg_0123456789abcdef",
                    "channel": "sms",
                    "sender_id": "snd_example01",
                    "destination": "+254712345678",
                    "status": "queued",
                    "revision": 1,
                    "purpose": "transactional",
                    "created_at": "2026-11-29T09:30:00Z",
                    "updated_at": "2026-11-29T09:30:00Z"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request, destination, content, or idempotency key. Error codes: INVALID_MESSAGE_ID.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "message"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The API key lacks the required permission. Error codes: PERMISSION_DENIED.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "The resource is unknown or inaccessible. Error codes: NOT_FOUND.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "The service is temporarily unavailable. Error codes: STATUS_UNAVAILABLE.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "code"
                          ]
                        },
                        "request_id": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "error",
                        "request_id"
                      ]
                    }
                  },
                  "required": [
                    "success",
                    "message",
                    "data"
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Use a scoped Bonga API key."
      }
    },
    "schemas": {
      "Sender": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^snd_[a-z0-9]{8,40}$"
          },
          "channel": {
            "type": "string",
            "enum": [
              "sms",
              "whatsapp",
              "email"
            ]
          },
          "type": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "address": {
            "type": "string",
            "description": "Display address when known."
          },
          "slot": {
            "type": "integer",
            "description": "SIM slot when reported. Send using the sender ID, not the slot."
          },
          "connection_id": {
            "type": "string"
          },
          "ready": {
            "type": "boolean"
          },
          "readiness_reason": {
            "const": "not_qualified",
            "description": "Configured in the workspace; unavailable for v2 submission."
          },
          "content_types": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "receive": {
            "type": "boolean"
          },
          "receipts": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "channel",
          "type",
          "label",
          "connection_id",
          "ready",
          "content_types",
          "receive",
          "receipts"
        ]
      },
      "Connection": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "channel": {
            "type": "string",
            "enum": [
              "sms",
              "whatsapp",
              "email"
            ]
          },
          "kind": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "ready": {
            "type": "boolean"
          },
          "readiness_reason": {
            "const": "not_qualified",
            "description": "Configured in the workspace; unavailable for v2 submission."
          },
          "revision": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "channel",
          "kind",
          "label",
          "ready"
        ]
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^msg_[a-f0-9]{16,64}$"
          },
          "workspace_id": {
            "type": "string"
          },
          "channel": {
            "type": "string",
            "enum": [
              "sms",
              "whatsapp",
              "email"
            ]
          },
          "sender_id": {
            "type": "string",
            "pattern": "^snd_[a-z0-9]{8,40}$"
          },
          "connection_id": {
            "type": "string"
          },
          "destination": {
            "type": "string"
          },
          "revision": {
            "type": "integer"
          },
          "purpose": {
            "type": "string"
          },
          "error": {
            "type": "object"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "enum": [
              "queued",
              "sent",
              "delivered",
              "read",
              "failed",
              "submission_unknown"
            ]
          }
        },
        "required": [
          "id",
          "channel",
          "sender_id",
          "destination",
          "revision",
          "status",
          "created_at",
          "updated_at"
        ]
      }
    }
  }
}
