{
    "openapi": "3.1.0",
    "info": {
        "title": "Vaani Backend API",
        "description": "Public API - Call Management Endpoints (Requires API Key Authentication)",
        "version": "2.0.0"
    },
    "servers": [
        {
            "url": "https://api.vaanivoice.ai",
            "description": "Vaani Backend API Server"
        }
    ],
    "paths": {
        "/api/trigger-call/": {
            "post": {
                "tags": ["calls"],
                "summary": "Create Dispatch",
                "description": "Create an outbound call.\n\n**Authentication:** Requires X-API-Key header",
                "operationId": "create_dispatch_api_trigger_call__post",
                "parameters": [
                    {
                        "name": "X-API-Key",
                        "in": "header",
                        "required": true,
                        "schema": { "type": "string", "title": "X-Api-Key" }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": { "$ref": "#/components/schemas/TriggerCallRequest" }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": { "$ref": "#/components/schemas/DispatchResponse" }
                            }
                        }
                    },
                    "422": {
                        "description": "Validation Error",
                        "content": {
                            "application/json": {
                                "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
                            }
                        }
                    }
                }
            }
        },
        "/api/call-history": {
            "get": {
                "tags": ["calls"],
                "summary": "Get Call History",
                "description": "Get call history. Shows all calls for the authenticated user's client.",
                "operationId": "get_call_history",
                "parameters": [
                    {
                        "name": "X-API-Key",
                        "in": "header",
                        "required": true,
                        "schema": { "type": "string", "title": "X-Api-Key" }
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "required": false,
                        "schema": { "type": "integer", "default": 1 }
                    },
                    {
                        "name": "page_size",
                        "in": "query",
                        "required": false,
                        "schema": { "type": "integer", "default": 50, "maximum": 200 }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": { "$ref": "#/components/schemas/CallHistoryResponse" }
                            }
                        }
                    },
                    "422": {
                        "description": "Validation Error",
                        "content": {
                            "application/json": {
                                "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
                            }
                        }
                    }
                }
            }
        },
        "/api/transcript/{call_id}": {
            "get": {
                "tags": ["calls"],
                "summary": "Get Transcript",
                "description": "Retrieve the transcript for a call.",
                "operationId": "get_transcript_api_transcript__call_id__get",
                "parameters": [
                    {
                        "name": "call_id",
                        "in": "path",
                        "required": true,
                        "schema": { "type": "string", "title": "Call Id" }
                    },
                    {
                        "name": "client_name",
                        "in": "query",
                        "required": false,
                        "schema": { "anyOf": [{ "type": "string" }, { "type": "null" }] }
                    },
                    {
                        "name": "X-API-Key",
                        "in": "header",
                        "required": true,
                        "schema": { "type": "string", "title": "X-Api-Key" }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": { "$ref": "#/components/schemas/TranscriptResponse" }
                            }
                        }
                    },
                    "422": {
                        "description": "Validation Error",
                        "content": {
                            "application/json": {
                                "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
                            }
                        }
                    }
                }
            }
        },
        "/api/stream/{call_id}": {
            "get": {
                "tags": ["calls"],
                "summary": "Stream Audio",
                "description": "Stream audio file from Azure Blob Storage.",
                "operationId": "stream_audio_api_stream__call_id__get",
                "parameters": [
                    {
                        "name": "call_id",
                        "in": "path",
                        "required": true,
                        "schema": { "type": "string", "title": "Call Id" }
                    },
                    {
                        "name": "X-API-Key",
                        "in": "header",
                        "required": true,
                        "schema": { "type": "string", "title": "X-Api-Key" }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": { "$ref": "#/components/schemas/StreamResponse" }
                            }
                        }
                    },
                    "422": {
                        "description": "Validation Error",
                        "content": {
                            "application/json": {
                                "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
                            }
                        }
                    }
                }
            }
        },
        "/api/call_details/{client}/{call_id}": {
            "get": {
                "tags": ["calls"],
                "summary": "Get Call Details",
                "description": "Get detailed call information including transcript, entities, and evaluation.",
                "operationId": "get_call_details_api_call_details__client___call_id__get",
                "parameters": [
                    {
                        "name": "client",
                        "in": "path",
                        "required": true,
                        "schema": { "type": "string", "title": "Client" }
                    },
                    {
                        "name": "call_id",
                        "in": "path",
                        "required": true,
                        "schema": { "type": "string", "title": "Call Id" }
                    },
                    {
                        "name": "X-API-Key",
                        "in": "header",
                        "required": true,
                        "schema": { "type": "string", "title": "X-Api-Key" }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": { "$ref": "#/components/schemas/CallDetailsResponse" }
                            }
                        }
                    },
                    "422": {
                        "description": "Validation Error",
                        "content": {
                            "application/json": {
                                "schema": { "$ref": "#/components/schemas/HTTPValidationError" }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "TriggerCallRequest": {
                "type": "object",
                "title": "TriggerCallRequest",
                "description": "Model for triggering an outbound call - PUBLIC API.",
                "required": ["agent_id", "contact_number", "name"],
                "properties": {
                    "agent_id": {
                        "type": "string",
                        "format": "uuid",
                        "title": "Agent ID",
                        "description": "UUID of the agent to handle the call. Obtain from Agent Config in the dashboard."
                    },
                    "contact_number": {
                        "type": "string",
                        "title": "Contact Number",
                        "description": "Contact number with country code (e.g., +919876543210)"
                    },
                    "name": {
                        "type": "string",
                        "title": "Name",
                        "description": "Customer name"
                    },
                    "voice": {
                        "type": "string",
                        "title": "Voice",
                        "description": "Voice preference (optional)",
                        "default": ""
                    },
                    "metadata": {
                        "type": "object",
                        "additionalProperties": true,
                        "title": "Metadata",
                        "description": "Template variables defined in the agent's prompt, injected at call time.",
                        "default": {}
                    },
                    "outbound_number": {
                        "anyOf": [{ "type": "string" }, { "type": "null" }],
                        "title": "Outbound Number",
                        "description": "Optional outbound caller ID to use (E.164 format). Overrides the default number assigned to the agent.",
                        "default": null
                    }
                }
            },
            "DispatchResponse": {
                "type": "object",
                "title": "DispatchResponse",
                "description": "Response model for dispatch operations.",
                "required": ["success"],
                "properties": {
                    "success": {
                        "type": "boolean",
                        "title": "Success",
                        "description": "Whether the operation succeeded"
                    },
                    "message": {
                        "anyOf": [{ "type": "string" }, { "type": "null" }],
                        "title": "Message",
                        "default": "Command processed"
                    },
                    "output": {
                        "anyOf": [{ "type": "object" }, { "type": "string" }, { "type": "null" }],
                        "title": "Output",
                        "description": "Contains agent_name and call_id on success"
                    },
                    "error": {
                        "anyOf": [{ "type": "string" }, { "type": "null" }],
                        "title": "Error"
                    }
                }
            },
            "HTTPValidationError": {
                "type": "object",
                "title": "HTTPValidationError",
                "properties": {
                    "detail": {
                        "type": "array",
                        "items": { "$ref": "#/components/schemas/ValidationError" }
                    }
                }
            },
            "ValidationError": {
                "type": "object",
                "title": "ValidationError",
                "required": ["loc", "msg", "type"],
                "properties": {
                    "loc": {
                        "type": "array",
                        "items": { "anyOf": [{ "type": "string" }, { "type": "integer" }] }
                    },
                    "msg": { "type": "string" },
                    "type": { "type": "string" }
                }
            },
            "CallHistoryResponse": {
                "type": "object",
                "additionalProperties": true,
                "title": "CallHistoryResponse"
            },
            "TranscriptResponse": {
                "type": "object",
                "additionalProperties": true,
                "title": "TranscriptResponse"
            },
            "CallDetailsResponse": {
                "type": "object",
                "additionalProperties": true,
                "title": "CallDetailsResponse"
            },
            "StreamResponse": {
                "type": "object",
                "additionalProperties": true,
                "title": "StreamResponse"
            }
        }
    }
}