{"openapi":"3.1.0","info":{"title":"Callio Brain Platform","description":"AI, DB, Auth, Agent Creator, V1 CRUD API","version":"4.0.0"},"paths":{"/":{"get":{"tags":["health"],"summary":"Root","description":"Health check and status.","operationId":"root__get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/health":{"get":{"tags":["health"],"summary":"Health Check","description":"Detailed health check with component status.","operationId":"health_check_health_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/phones":{"get":{"tags":["health"],"summary":"List Phones","description":"Lista skonfigurowanych numerów.","operationId":"list_phones_phones_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/transcripts/{business_id}":{"get":{"tags":["health"],"summary":"List Transcripts","description":"Lista transkrypcji dla biznesu.","operationId":"list_transcripts_transcripts__business_id__get","parameters":[{"name":"business_id","in":"path","required":true,"schema":{"type":"string","title":"Business Id"}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","default":20,"title":"Limit"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/leads/{business_id}":{"get":{"tags":["health"],"summary":"Get Leads","description":"Get all saved leads for a business.","operationId":"get_leads_leads__business_id__get","parameters":[{"name":"business_id","in":"path","required":true,"schema":{"type":"string","title":"Business Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/leads":{"get":{"tags":["health"],"summary":"Get All Leads","description":"Get leads from all businesses.","operationId":"get_all_leads_leads_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/api/conversations":{"get":{"tags":["v1-conversations"],"summary":"Get Conversations","description":"Pobierz listę rozmów. **Wymaga JWT** (SEC-1, WP7a Faza 2).\n\nOwner-scope: zwykły user widzi WYŁĄCZNIE rozmowy swoich agentów (zbiór\nagent_id wyliczony z tokenu, NIE z query paramu który klient może podrobić).\nAdmin (role=admin / db.is_admin) widzi wszystko.\n\n`agent_ids` z query działa już tylko jako dodatkowy FILTR po stronie usera\n(intersekcja z posiadanymi agentami) — nie może rozszerzyć dostępu.\n`user_id` z query jest IGNOROWANY jako źródło tożsamości (zostawiony w\nsygnaturze tylko dla kompatybilności starych klientów) — tożsamość bierzemy\nz `scope` (tokenu).\n\nW4 split-brain fix: under the PG backend the list comes from Postgres (RLS-scoped,\nfanned-out per business), NOT the stale conversations.json. An empty PG result returns\n{data:[],total:0} — it must NOT fall through to the JSON file. The JSON path below is the\nUNCHANGED rollback path for the non-PG backend.\n\nTRANSCRIPT-READ HARDENING (2026-06-16): when PG is the active backend, a TRANSIENT failure\n(PG path raised, or list_conversations returned None = \"inactive\") must NOT fall through to the\nstale conversations.json — that is exactly how the founder saw \"No transcript available\" / an\nempty list while the row sat in PG. Gate the JSON fallback on `pg_active()`: under PG we return\nan EMPTY envelope on a transient miss (the caller can retry), never stale JSON. JSON is reached\nONLY when PG is genuinely not the backend.","operationId":"get_conversations_api_conversations_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"status","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status"}},{"name":"source","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Source"}},{"name":"agent_ids","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Ids"}},{"name":"user_id","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"User Id"}},{"name":"is_emergency","in":"query","required":false,"schema":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Is Emergency"}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","default":50,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","default":0,"title":"Offset"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"post":{"tags":["v1-conversations"],"summary":"Create Conversation","description":"Utwórz nową rozmowę (upsert by id).\nUżywane przez V4 backend do wysyłania danych z passthrough i AI calls.\n\nSEC-2 (WP7a Faza 2): to ruch WEWNĘTRZNY backend→backend (Voice→Brain), nie\nuser. Zabezpieczony `verify_internal_secret` (nagłówek X-Internal-Secret), nie\nuser-JWT. W dev mode (brak INTERNAL_API_SECRET) dependency przepuszcza —\nzachowanie identyczne jak innych endpointów /internal.\n\nW4: under the PG backend this is a SINGLE-ROW upsert into ``calls`` (INSERT ...\nON CONFLICT (id) DO UPDATE) — no whole-array file rewrite, no global lock. The\ndeleted conversations[i]['appointment_id'] back-link is gone (linkage is now the\nappointments.call_id FK). The JSON path below is the rollback path (W6 deletes it).","operationId":"create_conversation_api_conversations_post","parameters":[{"name":"X-Internal-Secret","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"X-Internal-Secret"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationCreate"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/conversations/{conversation_id}":{"get":{"tags":["v1-conversations"],"summary":"Get Conversation","description":"Pobierz szczegóły rozmowy. **Wymaga JWT** (SEC-1, WP7a Faza 2).\n\nWeryfikuje własność obiektu (BOLA-guard): owner-A pytający o rozmowę\nowner-B dostaje 403; nieistniejące ID → 404. Admin widzi wszystko.\nReuse `_verify_conversation_access` (ta sama logika co PATCH/DELETE).","operationId":"get_conversation_api_conversations__conversation_id__get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"conversation_id","in":"path","required":true,"schema":{"type":"string","title":"Conversation Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"patch":{"tags":["v1-conversations"],"summary":"Update Conversation","description":"Aktualizuj rozmowę (np. zmień status). Wymaga JWT.","operationId":"update_conversation_api_conversations__conversation_id__patch","security":[{"HTTPBearer":[]}],"parameters":[{"name":"conversation_id","in":"path","required":true,"schema":{"type":"string","title":"Conversation Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"delete":{"tags":["v1-conversations"],"summary":"Delete Conversation","description":"Usuń rozmowę. Wymaga JWT.","operationId":"delete_conversation_api_conversations__conversation_id__delete","security":[{"HTTPBearer":[]}],"parameters":[{"name":"conversation_id","in":"path","required":true,"schema":{"type":"string","title":"Conversation Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/appointments":{"get":{"tags":["v1-appointments"],"summary":"Get Appointments","description":"Pobierz listę wizyt. **Wymaga JWT** (SEC-1, WP7a Faza 2).\n\nOwner-scope: zwykły user widzi WYŁĄCZNIE wizyty swoich agentów (zbiór\nagent_id z tokenu, NIE z query paramu). Admin widzi wszystko. `agent_ids`\nz query działa już tylko jako filtr zawężający; `user_id` z query ignorowany\njako źródło tożsamości (kompat. sygnatura).\n\nW4 split-brain fix: under the PG backend the list comes from Postgres (RLS-scoped, fanned-out\nper business), NOT the stale appointments.json. An empty PG result returns {data:[],total:0}\n— it must NOT fall through to the JSON file. JSON path below is the UNCHANGED non-PG rollback.","operationId":"get_appointments_api_appointments_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"status","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status"}},{"name":"date","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Date"}},{"name":"agent_ids","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Ids"}},{"name":"user_id","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"User Id"}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","default":50,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","default":0,"title":"Offset"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"post":{"tags":["v1-appointments"],"summary":"Create Appointment","description":"Utwórz nową wizytę.\n\nSEC-2 (WP7a Faza 2): dwustronna autoryzacja — internal voice flow\n(X-Internal-Secret) LUB user JWT z owner-scope. Patrz\n`_authorize_appointment_create`.","operationId":"create_appointment_api_appointments_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"X-Internal-Secret","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"X-Internal-Secret"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppointmentCreate"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/appointments/{appointment_id}":{"get":{"tags":["v1-appointments"],"summary":"Get Appointment","description":"Pobierz szczegóły wizyty. **Wymaga JWT** (SEC-1, WP7a Faza 2).\n\nWeryfikuje własność obiektu (BOLA-guard): owner-A pytający o wizytę owner-B\ndostaje 403; nieistniejące ID → 404. Admin widzi wszystko. Reuse\n`_verify_appointment_access` (ta sama logika co PATCH/DELETE).","operationId":"get_appointment_api_appointments__appointment_id__get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"appointment_id","in":"path","required":true,"schema":{"type":"string","title":"Appointment Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"patch":{"tags":["v1-appointments"],"summary":"Update Appointment","description":"Aktualizuj wizytę. Wymaga JWT.","operationId":"update_appointment_api_appointments__appointment_id__patch","security":[{"HTTPBearer":[]}],"parameters":[{"name":"appointment_id","in":"path","required":true,"schema":{"type":"string","title":"Appointment Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"delete":{"tags":["v1-appointments"],"summary":"Delete Appointment","description":"Usuń wizytę. Wymaga JWT.","operationId":"delete_appointment_api_appointments__appointment_id__delete","security":[{"HTTPBearer":[]}],"parameters":[{"name":"appointment_id","in":"path","required":true,"schema":{"type":"string","title":"Appointment Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/auth/login":{"post":{"tags":["v1-auth"],"summary":"Login","description":"Logowanie użytkownika.\nZwraca JWT access_token + user_id, is_admin i listę agent_ids.","operationId":"login_api_auth_login_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LoginRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/auth/me":{"get":{"tags":["v1-auth"],"summary":"Get Current User","description":"Pobierz dane zalogowanego użytkownika.\nWymaga JWT Bearer token w header Authorization.","operationId":"get_current_user_api_auth_me_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}},"security":[{"HTTPBearer":[]}]}},"/api/auth/password":{"put":{"tags":["v1-auth"],"summary":"Change Password","description":"Zmiana hasła zalogowanego użytkownika.\nWymaga JWT + aktualne hasło do weryfikacji.","operationId":"change_password_api_auth_password_put","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PasswordChangeRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/auth/set-password":{"post":{"tags":["v1-auth"],"summary":"Set Password","description":"Set a password WITHOUT requiring the current one — for users who logged in via\nphone-only FIRST login (CALLIO_TARGET_SPEC §2 — ZERO SMS). Auth = a valid JWT,\nwhich is only issued by /api/auth/login-phone while the account has no password\nyet (the number was verified via caller-ID on the inbound onboarding call).\n\nSetting the password DISABLES phone-only login: once password_hash is non-empty,\n/api/auth/login-phone returns 401 and the user must use /api/auth/login\n(phone + password). One-time first-entry, by design.","operationId":"set_password_api_auth_set_password_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SetPasswordRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/auth/set-email":{"post":{"tags":["v1-auth"],"summary":"Set Email","description":"Zapisz/aktualizuj email kontaktowy zalogowanego usera.\n\nCALLIO_TARGET_SPEC §2: email = OSOBNE pole (NIE login; login = numer telefonu).\nSłuży jako kanał resetu hasła / magic-link. Domyka lukę \"email UI-only\" z WP9 —\nwelcome.tsx zbierał email lokalnie, ale nie miał gdzie go wysłać.\n\nAuth = ważny JWT (401 bez). Email jest normalizowany + walidowany po stronie\nbazy (`normalize_email`). 400 gdy email niepoprawny; 409 gdy email zajęty przez\ninne konto (UNIQUE index — `set_user_email` zwraca False); 200 przy sukcesie.","operationId":"set_email_api_auth_set_email_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SetEmailRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/auth/set-timezone":{"post":{"tags":["v1-auth"],"summary":"Set Timezone","description":"Set/update the owner-local business timezone (IANA), then re-PATCH every agent's clock.\n\nShared by BOTH the first-login Welcome screen and the Receptionist settings card. Auth = a\nvalid JWT (401 without). 400 on a garbage/empty IANA name; 404 when the owner has no business\nyet. Writes BOTH the canonical business_info['timezone'] AND the synced top-level column,\nPERSIST-FIRST, then fans the prompt.timezone PATCH out to all non-deleted agents.\n\nReturns {success, timezone, agents_patched, agents_failed}. agents_failed is informational —\nbooking is already correct from the persisted value, and any failed agent reconciles on the\nnext owner edit (the fan-out runs on every set).","operationId":"set_timezone_api_auth_set_timezone_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SetTimezoneRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/auth/account":{"delete":{"tags":["v1-auth"],"summary":"Delete Account","description":"Permanently delete the logged-in user's account and ALL associated data.\n\nApple App Store Guideline 5.1.1(v) + GDPR art.17 / CCPA right-to-erasure.\nRequires a valid JWT (401 without). Idempotent and safe: the local DB cascade\nis atomic; external vendor cleanup (ElevenLabs agents, Twilio numbers, Stripe\nsubscription) is BEST-EFFORT and never blocks the deletion.\n\nCascade:\n  - cancel the active Stripe subscription (best-effort),\n  - delete the user's ElevenLabs agents + forget their caller memory,\n  - release dedicated Twilio number(s),\n  - purge conversations + appointments (JSON) for owned agents,\n  - delete push devices + referral footprint,\n  - HARD-delete users/agents/subscriptions/usage/payments/auth_tokens rows,\n  - write an account.delete audit entry.","operationId":"delete_account_api_auth_account_delete","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}},"security":[{"HTTPBearer":[]}]}},"/api/auth/account/export":{"get":{"tags":["v1-auth"],"summary":"Export Account","description":"GDPR data-portability export (art.20): the user's own data as JSON.\n\nRequires a valid JWT. Returns account, agents, subscription, and the\nconversations/appointments tied to the user's agents. Read-only.","operationId":"export_account_api_auth_account_export_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}},"security":[{"HTTPBearer":[]}]}},"/api/admin/search-user":{"get":{"tags":["v1-auth"],"summary":"Admin Search User","description":"Wyszukuje użytkownika po numerze telefonu (tylko dla admina).\nWymaga JWT Bearer token z rolą 'admin' (SEC-4 require_super_admin).","operationId":"admin_search_user_api_admin_search_user_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"phone","in":"query","required":true,"schema":{"type":"string","title":"Phone"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/costs":{"get":{"tags":["v1-costs"],"summary":"Get Costs","description":"Pobierz koszty rozmów (tylko dla admina).\nAgreguje koszty z cost_data rozmów per agent.","operationId":"get_costs_api_costs_get","parameters":[{"name":"user_id","in":"query","required":true,"schema":{"type":"string","title":"User Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/costs/details":{"get":{"tags":["v1-costs"],"summary":"Get Costs Details","description":"Pobierz szczegółowe koszty rozmów (tylko dla admina).\nZwraca listę rozmów z kosztami dla danego agenta.","operationId":"get_costs_details_api_costs_details_get","parameters":[{"name":"user_id","in":"query","required":true,"schema":{"type":"string","title":"User Id"}},{"name":"agent_id","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/subscription/{user_id}":{"get":{"tags":["v1-subscription"],"summary":"Get Subscription Status","description":"Pobiera status subskrypcji użytkownika.\nWymaga JWT. User może pobrać tylko swoje dane (lub admin dowolne).","operationId":"get_subscription_status_api_subscription__user_id__get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/usage/{user_id}":{"get":{"tags":["v1-subscription"],"summary":"Get Usage","description":"Pobiera zużycie minut użytkownika.\nWymaga JWT. User może pobrać tylko swoje dane (lub admin dowolne).","operationId":"get_usage_api_usage__user_id__get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/subscription/{user_id}/create-checkout":{"post":{"tags":["v1-subscription"],"summary":"Create Checkout Session","description":"Tworzy Stripe Checkout Session.\nWymaga JWT. User może tworzyć tylko dla siebie (lub admin dla kogokolwiek).","operationId":"create_checkout_session_api_subscription__user_id__create_checkout_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateCheckoutRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/subscription/{user_id}/buy-minutes":{"post":{"tags":["v1-subscription"],"summary":"Buy Minutes","description":"Dokup minut (top-up §3 / W5 gap 6, D1) po cenie/min planu usera (HARD CAP model).\n\nW5 (decyzja foundera D1): kupowalne są PAKIETY z config/plans.json\n(topup_packages: 50/150/400 min); cena = overage_per_min_usd planu × minuty\n(pełne centy). Pakiety można kupować wielokrotnie (stackują się); saldo NIE\nwygasa, dopóki subskrypcja aktywna (rollover przenosi niewykorzystaną część).\nTworzy jednorazowy Stripe Checkout (mode='payment'); po opłaceniu webhook\n(_handle_topup_completed) dolicza minuty do limitu ORAZ salda. Zwraca checkout_url.\nWymaga JWT. User może dokupić tylko sobie (lub admin dowolnemu).","operationId":"buy_minutes_api_subscription__user_id__buy_minutes_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BuyMinutesRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/subscription/{user_id}/change-plan/preview":{"get":{"tags":["v1-subscription"],"summary":"Preview Change Plan","description":"Podgląd zmiany planu PRZED potwierdzeniem (W4 pkt 3 / §A1 UI).\n\nUPGRADE: dokładna kwota dopłaty ZA TERAZ ze Stripe Invoice Preview\n(create_preview; pełna cena nowego planu minus kredyt za niewykorzystany czas\nstarego, ten sam proration_date co późniejszy modify — klient odsyła go w\nPOST /change-plan). DOWNGRADE: zero dopłat, wchodzi od następnego odnowienia.\nWymaga JWT. User może podejrzeć tylko swoją (lub admin dowolną).","operationId":"preview_change_plan_api_subscription__user_id__change_plan_preview_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}},{"name":"plan_id","in":"query","required":true,"schema":{"type":"string","title":"Plan Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/subscription/{user_id}/change-plan":{"post":{"tags":["v1-subscription"],"summary":"Change Plan","description":"Zmiana planu (W4, spec gapy 2+3):\n\nUPGRADE (§A1) — NATYCHMIAST: Stripe Subscription.modify z\nproration_behavior='always_invoice' + billing_cycle_anchor='now' +\npayment_behavior='pending_if_incomplete'. Karta odmówi -> Stripe NIE zmienia\nplanu (pending_update) i my NIE zmieniamy nic lokalnie (402). Po sukcesie\nENDPOINT deterministycznie ustawia lokalnie (A7.1): plan, minutes_limit =\nbaza nowego + saldo top-upów (D1: saldo przechodzi), minutes_used = 0, nowe\nokno okresu ze Stripe; webhooki tylko reconcilują. Faktura upgrade'u ma\nbilling_reason='subscription_update' — rollover odnowienia jej nie tknie.\n\nDOWNGRADE (§A2) — OD NASTĘPNEGO OKRESU: Stripe Subscription Schedule\n(end_behavior='release') przepina price przy odnowieniu; lokalnie tylko\npending_plan_id. Zero zwrotów/prorat. Undo = DELETE /change-plan do końca\nokresu. Ponowny wybór tego samego pending planu = idempotentny no-op.\n\nWymaga JWT. User może zmienić tylko swój plan (lub admin dowolny). Audited.","operationId":"change_plan_api_subscription__user_id__change_plan_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChangePlanRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"delete":{"tags":["v1-subscription"],"summary":"Undo Change Plan","description":"Cofa zaplanowany DOWNGRADE (W4 / §A2): release Stripe Subscription Schedule\n+ czyści lokalny pending_plan_id. Idempotentny — undo bez wiszącej zmiany to\nsukces (i tak reconciluje Stripe, gdyby schedule wisiał po rozjeździe; release\nhelper traktuje brak schedule'a jako no-op). Wymaga JWT. Audited.","operationId":"undo_change_plan_api_subscription__user_id__change_plan_delete","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/subscription/{user_id}/cancel":{"post":{"tags":["v1-subscription"],"summary":"Cancel Subscription","description":"Anuluje subskrypcję użytkownika — Z KOŃCEM OPŁACONEGO OKRESU (Billing W2, gap 4).\n\nPłatna subskrypcja (jest stripe_subscription_id): Stripe cancel_at_period_end=true,\nlokalnie status ZOSTAJE 'active' + trwała flaga cancel_at_period_end + data końca\nusługi. Faktyczne domknięcie robi webhook customer.subscription.deleted (istniejący\nhandler). Do końca okresu działa POST /resume. Ponowny cancel = idempotentny no-op.\n\nSubskrypcja bez Stripe (trial / nieopłacona): nie ma opłaconego okresu do\ndochodzenia — natychmiastowe lokalne 'cancelled' (zachowanie sprzed W2).\n\nWymaga JWT. User może anulować tylko swoją (lub admin dowolną).\nWP7a Faza 4: cancel is audited (action 'subscription.cancel') — sensitive,\nfinancial. Audit is best-effort (never blocks cancel).","operationId":"cancel_subscription_api_subscription__user_id__cancel_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelSubscriptionRequest","default":{}}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/subscription/{user_id}/resume":{"post":{"tags":["v1-subscription"],"summary":"Resume Subscription","description":"Cofa zaplanowane anulowanie subskrypcji (Billing W2, gap 8) — działa do końca\nopłaconego okresu (Stripe: cancel_at_period_end=false). Subskrypcji już\ndomkniętej (cancelled/expired) NIE da się wznowić — wymagany nowy checkout.\n\nIdempotentny: resume bez zaplanowanego anulowania = sukces (i tak reconciluje\nStripe, gdyby flaga rozjechała się np. po cancelu w Customer Portal).\nWymaga JWT. User może wznowić tylko swoją (lub admin dowolną). Audited.","operationId":"resume_subscription_api_subscription__user_id__resume_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/subscription/{user_id}/portal":{"post":{"tags":["v1-subscription"],"summary":"Get Customer Portal","description":"Generuje URL do Stripe Customer Portal.\nPortal pozwala użytkownikowi zarządzać metodą płatności, fakturami, anulowaniem.\nWymaga JWT. User dostaje tylko swój portal.","operationId":"get_customer_portal_api_subscription__user_id__portal_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PortalRequest","default":{}}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/payments/{user_id}":{"get":{"tags":["v1-subscription"],"summary":"Get Payments","description":"Pobiera historię płatności użytkownika.\nWymaga JWT. User może pobrać tylko swoje (lub admin dowolne).","operationId":"get_payments_api_payments__user_id__get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","default":20,"title":"Limit"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/webhook/stripe":{"post":{"tags":["v1-subscription"],"summary":"Handle Stripe Webhook","description":"Obsługuje webhooki od Stripe.\nNIE wymaga JWT — weryfikacja przez Stripe-Signature header.\nIdempotentny — powtórzony event jest ignorowany.","operationId":"handle_stripe_webhook_webhook_stripe_post","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/api/v2/availability":{"post":{"tags":["v1-booking"],"summary":"Check Availability","description":"Live availability read for the ElevenLabs `check_availability` webhook tool.\nNEVER 500s — always returns a `spoken` string the agent can say.","operationId":"check_availability_api_v2_availability_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AvailabilityRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v2/book":{"post":{"tags":["v1-booking"],"summary":"Book Appointment","description":"LIVE booking write for the ElevenLabs `book_appointment` webhook tool\n(W1/D2). Per the EL Cal.com reference flow the agent collects -> checks\navailability -> confirms explicitly -> calls THIS -> confirms only from the\ntool result.\n\nContract: NEVER 500s, ALWAYS 200 with {booked: bool, slot?, spoken}.\nSERVER-SIDE working-hours guardrail (booking_hours.validate_slot — single\nsource shared with the post-call extractor): out-of-hours / closed-day /\npast-date / slot-overruns-close NEVER creates a row; the spoken result\noffers the real next opening instead. In-hours -> in-txn capacity-guarded\ncreate (call_data_pg.create_appointment, the W4 TOCTOU killer) keyed with\ncall_id=conversation_id so the post-call extractor can never double-book\nthe same call (W1/D3 idempotency).","operationId":"book_appointment_api_v2_book_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BookRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v2/my_appointments":{"post":{"tags":["v1-booking"],"summary":"My Appointments","description":"LIVE caller booking-lookup for the `list_my_appointments` EL webhook tool.\nPhone-scoped to {{caller_phone}} (last-10 match) — a caller only ever sees their OWN.\nNEVER 500s — always 200 with a `spoken` string.","operationId":"my_appointments_api_v2_my_appointments_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MyAppointmentsRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v2/cancel":{"post":{"tags":["v1-booking"],"summary":"Cancel My Appointment","description":"LIVE caller booking-CANCEL for the `cancel_my_appointment` EL webhook tool.\nPhone-scoped to {{caller_phone}} (last-10 match) — a caller can ONLY cancel their own.\nRefuses if the booking starts within the owner-configured advance-notice window (default\n24h). NEVER 500s — always 200 with {cancelled: bool, spoken}.","operationId":"cancel_my_appointment_api_v2_cancel_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v2/reschedule":{"post":{"tags":["v1-booking"],"summary":"Reschedule My Appointment","description":"LIVE caller booking-RESCHEDULE for the `reschedule_my_appointment` EL webhook tool\n(2026-06-16). A MOVE is a capability SEPARATE from cancel: phone-scoped to {{caller_phone}}\n(last-10 match — a caller can ONLY move their own), gated by its OWN advance-notice window\n(default 1h, distinct from cancel's 24h) applied to the EXISTING booking's start, and the\nNEW slot is validated against working hours + the business-LOCAL current time (no past\ntarget). NEVER 500s — always 200 with {rescheduled: bool, spoken, [ambiguous]}.","operationId":"reschedule_my_appointment_api_v2_reschedule_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RescheduleRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/agents/voices":{"get":{"tags":["agents"],"summary":"Get Voices","description":"Pobiera liste dostepnych glosow.\n\nZwraca liste 3 przetestowanych glosow:\n- Profesjonalna kobieta (Sarah)\n- Profesjonalny mezczyzna (Polski Asystent)\n- Przyjazna kobieta (Gigi)","operationId":"get_voices_api_agents_voices_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"items":{"$ref":"#/components/schemas/VoiceResponse"},"type":"array","title":"Response Get Voices Api Agents Voices Get"}}}}}}},"/api/agents":{"get":{"tags":["agents"],"summary":"Get Agents","description":"Pobiera liste agentow uzytkownika.\n\nArgs:\n    agent_ids: Comma-separated lista dozwolonych agent_ids (z frontendu auth store).\n               Jesli puste, zwraca pusta liste (bezpieczenstwo multi-tenant!).\n\nZwraca podstawowe informacje o kazdym agencie.\nDla pelnej konfiguracji uzyj GET /api/agents/{agent_id}","operationId":"get_agents_api_agents_get","parameters":[{"name":"agent_ids","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Ids"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/AgentListItem"},"title":"Response Get Agents Api Agents Get"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/agents/{agent_id}":{"get":{"tags":["agents"],"summary":"Get Agent Config","description":"Pobiera pelna konfiguracje agenta.\n\nAuthorization:\n    - Bearer token w header Authorization (JWT)\n    - Lub agent_ids query param dla backwards compatibility\n\nArgs:\n    agent_id: ID agenta do pobrania\n    agent_ids: Comma-separated lista dozwolonych agent_ids (backwards compatibility).\n               Agent musi byc na tej liscie zeby go pobrac.\n    current_user_id: ID uzytkownika z JWT tokenu (automatycznie z header)\n\nZawiera:\n- Ustawienia glosu (voice_id, speed)\n- Powitanie (first_message)\n- Sparsowane pola prompta (FAQ, pytania, pozegnanie)\n- Tresc prompta do trybu zaawansowanego (editable_prompt)\n- Role agenta (is_router okresla czy ma sekcje FAQ/questions)\n\nNote:\n    Jesli agent jest routerem (is_router=True), pola FAQ i questions\n    beda puste - router tylko klasyfikuje, nie zbiera danych.","operationId":"get_agent_config_api_agents__agent_id__get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"agent_id","in":"path","required":true,"schema":{"type":"string","title":"Agent Id"}},{"name":"agent_ids","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Ids"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentConfigResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"put":{"tags":["agents"],"summary":"Update Agent","description":"Aktualizuje konfiguracje agenta.\n\nAuthorization:\n    - Bearer token w header Authorization (JWT)\n    - Lub agent_ids query param dla backwards compatibility\n\nArgs:\n    agent_id: ID agenta do aktualizacji\n    update: Dane do aktualizacji\n    agent_ids: Comma-separated lista dozwolonych agent_ids (backwards compatibility).\n    current_user_id: ID uzytkownika z JWT tokenu (automatycznie z header)\n\nMozna aktualizowac:\n- voice_id: Glos (musi byc z listy dozwolonych)\n- first_message: Tekst powitania\n- faq: Lista FAQ [{question, answer}]\n- questions: Pytania [{field, prompt}]\n- speed: Szybkosc mowienia (0.7-1.2)\n- eagerness: Styl (patient|normal|eager)\n- prompt_text: Pelny prompt (tryb zaawansowany)\n- goodbye: Tekst pozegnania\n\nNote:\n    Router (is_router=True) nie powinien miec aktualizowanych FAQ i questions.\n    Frontend powinien ukryc te pola dla routerow.\n\nRaises:\n    400: Nieprawidlowe parametry (np. zly voice_id, zly zakres speed)\n    401: Brak autoryzacji\n    403: Brak dostepu\n    404: Agent nie istnieje\n    500: Blad aktualizacji w ElevenLabs","operationId":"update_agent_api_agents__agent_id__put","security":[{"HTTPBearer":[]}],"parameters":[{"name":"agent_id","in":"path","required":true,"schema":{"type":"string","title":"Agent Id"}},{"name":"agent_ids","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Ids"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentUpdateRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"delete":{"tags":["agents"],"summary":"Delete Agent","description":"Usuwa agenta (soft delete — ustawia status 'deleted').\n\nWymaga JWT. User może usunąć tylko swoich agentów (lub admin dowolnych).\nNie usuwa fizycznie z ElevenLabs — zmienia status w lokalnej bazie.","operationId":"delete_agent_api_agents__agent_id__delete","security":[{"HTTPBearer":[]}],"parameters":[{"name":"agent_id","in":"path","required":true,"schema":{"type":"string","title":"Agent Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/sales/auth/login":{"post":{"tags":["sales"],"summary":"Sales Login","operationId":"sales_login_api_sales_auth_login_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SalesLoginRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SalesLoginResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/sales/auth/me":{"get":{"tags":["sales"],"summary":"Sales Me","operationId":"sales_me_api_sales_auth_me_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SalesRepPublic"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/sales/leads":{"post":{"tags":["sales"],"summary":"Create Lead","operationId":"create_lead_api_sales_leads_post","security":[{"HTTPBearer":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LeadCreate"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LeadResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"get":{"tags":["sales"],"summary":"List My Leads","operationId":"list_my_leads_api_sales_leads_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"status","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status"}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","maximum":500,"minimum":1,"default":100,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"default":0,"title":"Offset"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/LeadResponse"},"title":"Response List My Leads Api Sales Leads Get"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/sales/leads/{lead_id}":{"get":{"tags":["sales"],"summary":"Get Lead","operationId":"get_lead_api_sales_leads__lead_id__get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"lead_id","in":"path","required":true,"schema":{"type":"string","title":"Lead Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LeadResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"patch":{"tags":["sales"],"summary":"Update Lead Endpoint","operationId":"update_lead_endpoint_api_sales_leads__lead_id__patch","security":[{"HTTPBearer":[]}],"parameters":[{"name":"lead_id","in":"path","required":true,"schema":{"type":"string","title":"Lead Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LeadUpdate"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LeadResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"delete":{"tags":["sales"],"summary":"Delete Lead Endpoint","operationId":"delete_lead_endpoint_api_sales_leads__lead_id__delete","security":[{"HTTPBearer":[]}],"parameters":[{"name":"lead_id","in":"path","required":true,"schema":{"type":"string","title":"Lead Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/sales/earnings/summary":{"get":{"tags":["sales"],"summary":"Get My Earnings Summary","operationId":"get_my_earnings_summary_api_sales_earnings_summary_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/EarningsSummary"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/sales/earnings":{"get":{"tags":["sales"],"summary":"List My Commissions","operationId":"list_my_commissions_api_sales_earnings_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"items":{"$ref":"#/components/schemas/CommissionResponse"},"type":"array","title":"Response List My Commissions Api Sales Earnings Get"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/sales/payouts/request":{"post":{"tags":["sales"],"summary":"Request Payout","operationId":"request_payout_api_sales_payouts_request_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayoutRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayoutResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/sales/payouts":{"get":{"tags":["sales"],"summary":"List My Payouts","operationId":"list_my_payouts_api_sales_payouts_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"items":{"$ref":"#/components/schemas/PayoutResponse"},"type":"array","title":"Response List My Payouts Api Sales Payouts Get"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/sales/dashboard":{"get":{"tags":["sales"],"summary":"Get My Dashboard","operationId":"get_my_dashboard_api_sales_dashboard_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RepDashboard"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/sales/admin/dashboard":{"get":{"tags":["sales"],"summary":"Admin Dashboard","operationId":"admin_dashboard_api_sales_admin_dashboard_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdminDashboard"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/sales/admin/workers":{"get":{"tags":["sales"],"summary":"List Workers","operationId":"list_workers_api_sales_admin_workers_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"include_inactive","in":"query","required":false,"schema":{"type":"boolean","default":false,"title":"Include Inactive"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/WorkerSummary"},"title":"Response List Workers Api Sales Admin Workers Get"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"post":{"tags":["sales"],"summary":"Create Worker","operationId":"create_worker_api_sales_admin_workers_post","security":[{"HTTPBearer":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateWorkerRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SalesRepPublic"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/sales/admin/workers/{worker_id}":{"get":{"tags":["sales"],"summary":"Get Worker Detail","operationId":"get_worker_detail_api_sales_admin_workers__worker_id__get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"worker_id","in":"path","required":true,"schema":{"type":"string","title":"Worker Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WorkerDetail"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"patch":{"tags":["sales"],"summary":"Update Worker","operationId":"update_worker_api_sales_admin_workers__worker_id__patch","security":[{"HTTPBearer":[]}],"parameters":[{"name":"worker_id","in":"path","required":true,"schema":{"type":"string","title":"Worker Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateWorkerRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SalesRepPublic"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"delete":{"tags":["sales"],"summary":"Deactivate Worker","operationId":"deactivate_worker_api_sales_admin_workers__worker_id__delete","security":[{"HTTPBearer":[]}],"parameters":[{"name":"worker_id","in":"path","required":true,"schema":{"type":"string","title":"Worker Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/sales/admin/leads":{"get":{"tags":["sales"],"summary":"Admin List All Leads","operationId":"admin_list_all_leads_api_sales_admin_leads_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"status","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status"}},{"name":"sales_rep_id","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Sales Rep Id"}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","maximum":500,"minimum":1,"default":100,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"default":0,"title":"Offset"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/LeadResponse"},"title":"Response Admin List All Leads Api Sales Admin Leads Get"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/sales/admin/payouts":{"get":{"tags":["sales"],"summary":"Admin List Payouts","operationId":"admin_list_payouts_api_sales_admin_payouts_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"status","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/PayoutResponse"},"title":"Response Admin List Payouts Api Sales Admin Payouts Get"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/sales/admin/payouts/{payout_id}":{"patch":{"tags":["sales"],"summary":"Admin Update Payout","operationId":"admin_update_payout_api_sales_admin_payouts__payout_id__patch","security":[{"HTTPBearer":[]}],"parameters":[{"name":"payout_id","in":"path","required":true,"schema":{"type":"string","title":"Payout Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayoutAdminUpdate"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayoutResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/public/demo-request":{"post":{"tags":["v1-public"],"summary":"Request Demo","description":"Public endpoint — prospect requests a demo call.\nRate limited: max 3 requests per IP per hour.\nHoneypot field must be empty (anti-spam).","operationId":"request_demo_api_public_demo_request_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DemoRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/public/lead":{"post":{"tags":["v1-public"],"summary":"Capture Lead","description":"Public endpoint — capture a landing-page email lead. No auth.\n\nHoneypot ``hp`` non-empty -> silent 200 (bot, dropped). Rate limited per IP\n(fail-OPEN: a Redis blip must never break lead capture). Dedup by email;\nreturns {\"ok\": true} on both a fresh insert and a duplicate. Fires NO call/SMS\nto the lead — the only side effect is the INTERNAL founder alert email (W20),\nscheduled as a background task on a fresh email or a callback-intent submit.","operationId":"capture_lead_api_public_lead_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LeadRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/public/stats":{"get":{"tags":["v1-public"],"summary":"Get Public Stats","description":"Public statistics for landing page display.\nReturns general stats (not sensitive data).","operationId":"get_public_stats_api_public_stats_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/api/public/demo-agent-config":{"get":{"tags":["v1-public"],"summary":"Get Demo Agent Config","description":"Returns configuration for ElevenLabs demo widget.\nOnly exposes the public agent ID, nothing sensitive.","operationId":"get_demo_agent_config_api_public_demo_agent_config_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/api/public/founding-offer":{"get":{"tags":["v1-public"],"summary":"Get Founding Offer","description":"Public founding-offer state — live counter from the Stripe promotion code.\n\nWire contract (frozen by tests/test_founding_offer_endpoint.py):\n  active offer : {\"active\": true,  \"remaining\": 7, \"total\": 10, \"code\": \"FOUNDING33\"}\n  hidden       : {\"active\": false, \"remaining\": 0, \"total\": 10, \"code\": null}\nAlways HTTP 200 (never-500 hardening). The code string comes from Stripe\n(single source of truth) — it is NOT read from env.\n\nFlow (blueprint §2.1): blank env => hidden (founder kill-switch; second\nkill-switch = archiving the code in the Stripe dashboard => active=false)\n-> fresh Redis cache (60s) -> PromotionCode.retrieve -> cache fresh+stale\n-> exhaustion alert check. Stripe error => stale cache (<=15 min) =>\nhidden. No stale-cache lying: stale is only ever a previously-true payload.","operationId":"get_founding_offer_api_public_founding_offer_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/api/referrals":{"get":{"tags":["referrals"],"summary":"Get My Referral","description":"Zwraca mój kod referral (jeśli istnieje) + status programu.\n\nStatus: ilu poleconych zapłaciło, ile nagród naliczono / oczekuje. Nie tworzy\nkodu (do tego POST) — pozwala apce pokazać ekran nawet przed wygenerowaniem.","operationId":"get_my_referral_api_referrals_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}},"security":[{"HTTPBearer":[]}]},"post":{"tags":["referrals"],"summary":"Create My Referral","description":"Generuje JEDNORAZOWY kod referral usera (idempotentnie).\n\nJeśli user już ma kod — zwraca istniejący (nie tworzy drugiego w Stripe).\nInaczej: rezerwuje kod w bazie, tworzy/uzyskuje współdzielony Coupon -$50 oraz\nunikalny PromotionCode (max_redemptions=1, first_time_transaction) i zapisuje ID.","operationId":"create_my_referral_api_referrals_post","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}},"security":[{"HTTPBearer":[]}]}},"/api/devices/register":{"post":{"tags":["devices"],"summary":"Register Device","description":"Zarejestruj (upsert) token push dla zalogowanego użytkownika.","operationId":"register_device_api_devices_register_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeviceRegister"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/devices/unregister":{"post":{"tags":["devices"],"summary":"Unregister Device","description":"Usuń token (np. przy wylogowaniu).","operationId":"unregister_device_api_devices_unregister_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeviceUnregister"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/devices":{"get":{"tags":["devices"],"summary":"List Devices","operationId":"list_devices_api_devices_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}},"security":[{"HTTPBearer":[]}]}},"/api/plans":{"get":{"tags":["plans"],"summary":"List Plans","description":"Publiczny cennik — dla ekranu subskrypcji w apce i strony z cennikiem.","operationId":"list_plans_api_plans_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/api/plans/{plan_id}":{"get":{"tags":["plans"],"summary":"Get Single Plan","operationId":"get_single_plan_api_plans__plan_id__get","parameters":[{"name":"plan_id","in":"path","required":true,"schema":{"type":"string","title":"Plan Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/auth/account-status":{"get":{"tags":["auth-phone"],"summary":"Account Status","description":"Lets the app show the right state BEFORE login (§2):\n  - ready_no_password : account exists, password NOT set yet -> first entry =\n                        phone-only login (POST /api/auth/login-phone)\n  - ready             : password set -> log in with phone + password\n                        (POST /api/auth/login)\n  - processing        : NO account yet, BUT a creation workflow is in flight for\n                        this number — surfaced from the START of creation (the\n                        Redis ``provision:{phone}`` marker set before step [1/7])\n                        OR a FRESH durable pending_agents row (whichever fires\n                        first; either alone is enough). The Mia onboarding call is\n                        being turned into an assistant. The app shows \"we're\n                        setting up your assistant\" and auto-polls until ready.\n  - setup_failed      : NO account, and the freshest signal for this number is a\n                        RECENT failed (or silently-died) creation attempt. The app\n                        shows an honest \"something went wrong — call our line again\"\n                        instead of pretending the number was never seen.\n  - unavailable       : none of the above — unknown number, or any failure older\n                        than PENDING_FAILED_VISIBLE_HOURS.\n\nSECURITY / anti-enumeration (CONSCIOUSLY REVISED, Wave B 2026-06-11): this endpoint is\npublic, so it is rate-limited per-IP + per-number (same fail-CLOSED limiters as\n/api/auth/login-phone). Surfacing 'processing' re-exposes \"this number just onboarded\"\n— but that distinction is ALREADY observable on POST /api/auth/login-phone (409 vs\n404), and the same per-number throttle gates it here. 'setup_failed' (NEW) does widen\nthe oracle to \"this number called us and creation failed, within the last 24 h\":\naccepted deliberately — the founder requires an honest failure state (a failed\nonboarding masquerading as \"no account\" cost a live onboarding on 2026-06-11), the\nwindow is bounded (PENDING_FAILED_VISIBLE_HOURS, then coarse 'unavailable' again),\nthe same throttles apply, and the response NEVER echoes the internal error_message\n(static copy only). A number older than the window stays indistinguishable from a\nnever-seen one.","operationId":"account_status_api_auth_account_status_get","parameters":[{"name":"phone","in":"query","required":true,"schema":{"type":"string","title":"Phone"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/auth/login-phone":{"post":{"tags":["auth-phone"],"summary":"Login Phone","description":"Passwordless FIRST login (§2): log in with the phone number ONLY, allowed exactly\nonce — while the account exists but no password has been set yet. The number was\nverified via caller-ID during the inbound onboarding call.\n\nReturns the same JWT payload shape as /api/auth/login. After the user sets a\npassword (/api/auth/set-password), this endpoint returns 401 and they must use\n/api/auth/login (phone + password).\n\nRate-limited (WP7a Faza 3): per-IP via the route dependency (rate_limit_login_phone)\n+ per-number here (rate_limit_login_phone_number). body.phone is already E.164-\nnormalized by PhoneBody's validator, so the per-number key is canonical. Both are\nfail-CLOSED on a Redis outage (auth surface). Limits enumeration of account states\n(404/401/409) and the passwordless takeover window.","operationId":"login_phone_api_auth_login_phone_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PhoneBody"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/auth/forgot-password":{"post":{"tags":["auth-reset"],"summary":"Forgot Password","description":"Start a password reset. ALWAYS returns the same generic 200 (anti-enumeration).\n\nA reset email is sent ONLY when a matching account has an email on file.","operationId":"forgot_password_api_auth_forgot_password_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ForgotBody"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/auth/reset-password":{"post":{"tags":["auth-reset"],"summary":"Reset Password","description":"Consume a 'reset' token and set a new password (min 6 chars). Single-use.","operationId":"reset_password_api_auth_reset_password_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ResetBody"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/auth/login-token":{"post":{"tags":["auth-reset"],"summary":"Login Token","description":"Consume a 'login_link' magic-link token and issue a JWT (single-use).\n\nSAFER than phone-only first login (§2): proves control of the email collected on\nthe onboarding call. Frontend still forces set email+password afterwards when the\naccount has no password yet (needs_password flag).","operationId":"login_token_api_auth_login_token_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LoginTokenBody"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/phone-settings":{"get":{"tags":["phone-settings"],"summary":"Get Phone Settings","operationId":"get_phone_settings_api_phone_settings_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}},"security":[{"HTTPBearer":[]}]},"put":{"tags":["phone-settings"],"summary":"Update Phone Settings","operationId":"update_phone_settings_api_phone_settings_put","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PhoneSettingsUpdate"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/test-call/token":{"post":{"tags":["test-call"],"summary":"Get Test Call Token","description":"Wystawia krótkożyjący WebRTC token EL do testu in-app agenta usera.\n\nKroki:\n  (a) weryfikacja własności agenta (izolacja — NIE cudzy agent),\n  (b) check trialu (check_call_permission) — 403 z jasnym powodem gdy\n      wyczerpany ('trial_exhausted') / wygasły ('trial_expired'),\n  (c) EL conversational_ai.conversations.get_webrtc_token(agent_id=...) ->\n      token oddany do frontu (sync SDK -> asyncio.to_thread).","operationId":"get_test_call_token_api_test_call_token_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestCallTokenRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestCallTokenResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/test-call/release":{"post":{"tags":["test-call"],"summary":"Release Test Call","description":"Free THIS user's live test-session slot the instant the WebRTC call ends.\n\nSTUCK-SESSION SELF-HEAL (the bug this fixes): a browser/WebRTC crash before the EL\npost-call webhook fired left the per-user concurrency slot SET, so every retry hit\n`POST /api/test-call/token` -> 429 \"session already active\" until the slot's deadline\n+ ghost-sweeper finally purged it (~75s..~8min). The frontend now calls this on every\nteardown path (hangup / SDK error / disconnect / unmount / tab-hide) with the\n`release_token` it got at mint time, collapsing that window to ~instant.\n\nContract — deliberately forgiving so teardown can fire it 2-4× without harm:\n  * user_id is taken from the JWT, NEVER the body (a token can only free a slot under\n    the caller's OWN key — no cross-tenant release),\n  * NONCE-TARGETED ZREM (release_test_slot_by_nonce), NOT ZPOPMIN: it frees exactly\n    this session and never pops a *newer* live slot (which would wrongly admit a 3rd\n    concurrent session — a spend regression),\n  * idempotent: releasing an already-freed / unknown / stale nonce returns released=False,\n  * ALWAYS 200 — even with no token, nothing removed, or Redis down (best-effort; the\n    TTL/sweeper remain the backstop). It must NEVER 4xx/5xx and block the client teardown.","operationId":"release_test_call_api_test_call_release_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestCallReleaseRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestCallReleaseResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/test-call/state":{"get":{"tags":["test-call"],"summary":"Get Test Call State","description":"Stan 1st/2nd call dla agenta usera — front gatuje przyciski.\n\ncan_first_call  = trial aktywny (zawsze można zacząć).\ncan_second_call = call_count >= 1 (agent JUŻ coś zapamiętał po 1. rozmowie).\nremembered_name = imię zapamiętane przez agenta (opener przy 2. rozmowie).\n\nPamięć kluczowana (agent_id, phone_e164=numer usera) — izolacja jak inbound.","operationId":"get_test_call_state_api_test_call_state_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"agent_id","in":"query","required":true,"schema":{"type":"string","description":"ID agenta usera","title":"Agent Id"},"description":"ID agenta usera"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestCallStateResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/settings":{"get":{"tags":["admin-settings"],"summary":"Get Admin Settings","description":"Return current global settings (admin-only).","operationId":"get_admin_settings_api_admin_settings_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdminSettingsResponse"}}}}},"security":[{"HTTPBearer":[]}]},"put":{"tags":["admin-settings"],"summary":"Update Admin Settings","description":"Set the global base LLM model and/or the admin favorites (admin-only, live).\n\n- base_agent_llm_model is validated against the SDK Llm literal (offline,\n  authoritative) so we never persist a model EL would reject at create time.\n- favorite_llm_models are validated the same way; any invalid id is rejected\n  (fail explicit rather than silently drop, so the admin sees the typo).\n\nWP7a Faza 4: each applied change is written to the append-only audit log\n(action 'admin.settings.update', before/after in detail). Audit is best-effort\n(record_audit never raises) so it can't break the settings write.","operationId":"update_admin_settings_api_admin_settings_put","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdminSettingsUpdate"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdminSettingsResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/admin/llm-models":{"get":{"tags":["admin-settings"],"summary":"Get Llm Models","description":"List available LLM models for agent prompt.llm (admin-only).\n\nSource order: LIVE from ElevenLabs (conversational_ai.llm.list, EL SDK 2.50)\n-> CURATED SDK-derived fallback. ``source`` tells the UI which one it got.\n``refresh=true`` bypasses the in-process cache.","operationId":"get_llm_models_api_admin_llm_models_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"refresh","in":"query","required":false,"schema":{"type":"boolean","default":false,"title":"Refresh"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LlmModelsResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/audit-log":{"get":{"tags":["admin-settings"],"summary":"Get Audit Log","description":"Append-only audit log of sensitive admin/system actions (admin-only).\n\nCALLIO_ADMIN_PANEL_SPEC §2.9 — backs the WP7b panel audit viewer. Server-side\npagination (limit/offset) + optional filters by `action` and `actor`. There is\nNO PUT/DELETE counterpart: the table is append-only (DB triggers reject any\nUPDATE/DELETE), so this endpoint can only read history, never mutate it.","operationId":"get_audit_log_api_admin_audit_log_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":"integer","maximum":500,"minimum":1,"default":50,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"default":0,"title":"Offset"}},{"name":"action","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Exact action filter, e.g. 'admin.settings.update'","title":"Action"},"description":"Exact action filter, e.g. 'admin.settings.update'"},{"name":"actor","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Filter by actor user_id","title":"Actor"},"description":"Filter by actor user_id"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AuditLogResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/users":{"get":{"tags":["admin"],"summary":"Admin List Users","description":"List tenants — server-side pagination + search + filter + sort (M2, scalable).\n\nReplaces the old flat GET /api/admin/users (v1_auth, capped at 500, no paging).\nThe legacy endpoint stays for backward-compat; THIS one is the scalable path.","operationId":"admin_list_users_api_admin_users_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":"integer","maximum":200,"minimum":1,"default":50,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"default":0,"title":"Offset"}},{"name":"q","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Search by phone or email (substring, case-insensitive)","title":"Q"},"description":"Search by phone or email (substring, case-insensitive)"},{"name":"status","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Filter by account status (active|suspended|...)","title":"Status"},"description":"Filter by account status (active|suspended|...)"},{"name":"has_subscription","in":"query","required":false,"schema":{"anyOf":[{"type":"boolean"},{"type":"null"}],"description":"True=only with subscription, False=only without","title":"Has Subscription"},"description":"True=only with subscription, False=only without"},{"name":"sort","in":"query","required":false,"schema":{"type":"string","description":"created_at|last_login|phone|status","default":"created_at","title":"Sort"},"description":"created_at|last_login|phone|status"},{"name":"order","in":"query","required":false,"schema":{"type":"string","description":"asc|desc","default":"desc","title":"Order"},"description":"asc|desc"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TenantListResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/users/{user_id}":{"get":{"tags":["admin"],"summary":"Admin Get User Detail","description":"Tenant detail: subscription, agents, usage, number, email (M2).","operationId":"admin_get_user_detail_api_admin_users__user_id__get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TenantDetailResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/users/{user_id}/impersonate":{"post":{"tags":["admin"],"summary":"Admin Impersonate User","description":"Issue a SHORT-LIVED acting-as-user token (M3, audited).\n\nThe token carries role='user' (NOT admin — impersonation grants ZERO admin\nrights) plus an extra claim impersonated_by=<admin_id> so every action taken\nwith it is attributable to the real admin (§3.7). TTL is short (30 min). The\nadmin's own admin token is unaffected.\n\nrecord_audit('user.impersonate') — best-effort, never blocks issuing.","operationId":"admin_impersonate_user_api_admin_users__user_id__impersonate_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"path","required":true,"schema":{"type":"string","title":"User Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ImpersonateResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/impersonate/end":{"post":{"tags":["admin"],"summary":"Admin Impersonate End","description":"Mark the end of an impersonation session (audit only — token is stateless).\n\nThe acting-as token is short-lived and self-expiring; this endpoint records\n'user.impersonate.end' so the start/stop pair is in the audit trail (§3.7).","operationId":"admin_impersonate_end_api_admin_impersonate_end_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"user_id","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"The impersonated user_id (for audit)","title":"User Id"},"description":"The impersonated user_id (for audit)"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/costs/summary":{"get":{"tags":["admin"],"summary":"Admin Costs Summary","description":"Aggregated cost/margin dashboard (M4, §3.4).\n\nCOGS = sum of EL/Twilio/Anthropic from cost_tracker (call_costs) over the date\nrange. Revenue = current MRR proxy from ACTIVE subscriptions (plans.json price).\nMargin = revenue - COGS. Aggregates only — NOT per-record (scale: hundreds of\ntenants). Per-agent top spenders included for the margin watch-list.","operationId":"admin_costs_summary_api_admin_costs_summary_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"date_from","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"YYYY-MM-DD inclusive lower bound","title":"Date From"},"description":"YYYY-MM-DD inclusive lower bound"},{"name":"date_to","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"YYYY-MM-DD inclusive upper bound","title":"Date To"},"description":"YYYY-MM-DD inclusive upper bound"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CostSummaryResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/subscriptions":{"get":{"tags":["admin"],"summary":"Admin List Subscriptions","description":"Cross-tenant subscriptions — pagination + filter status/plan + sort (M6).","operationId":"admin_list_subscriptions_api_admin_subscriptions_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":"integer","maximum":200,"minimum":1,"default":50,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"default":0,"title":"Offset"}},{"name":"status","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Filter: trial|active|cancelled|expired","title":"Status"},"description":"Filter: trial|active|cancelled|expired"},{"name":"plan","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Filter by plan id","title":"Plan"},"description":"Filter by plan id"},{"name":"sort","in":"query","required":false,"schema":{"type":"string","description":"created_at|updated_at|plan|status","default":"created_at","title":"Sort"},"description":"created_at|updated_at|plan|status"},{"name":"order","in":"query","required":false,"schema":{"type":"string","description":"asc|desc","default":"desc","title":"Order"},"description":"asc|desc"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SubscriptionListResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/payments":{"get":{"tags":["admin"],"summary":"Admin List Payments","description":"Cross-tenant payments — pagination + filter status (M6).","operationId":"admin_list_payments_api_admin_payments_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":"integer","maximum":200,"minimum":1,"default":50,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"default":0,"title":"Offset"}},{"name":"status","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Filter: succeeded|refunded|failed|disputed","title":"Status"},"description":"Filter: succeeded|refunded|failed|disputed"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PaymentListResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/subscriptions/{subscription_id}/refund":{"post":{"tags":["admin"],"summary":"Admin Refund Subscription","description":"Refund the latest payment of a subscription via Stripe (M6, audited).\n\nLooks up the subscription, finds its most recent SUCCEEDED payment, calls\nStripe refund (mocked in tests), marks the local payment 'refunded', and\nrecords 'subscription.refund' in the append-only audit log. Stripe is the\nsource of truth for the money movement — we only mirror state + link out.","operationId":"admin_refund_subscription_api_admin_subscriptions__subscription_id__refund_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"subscription_id","in":"path","required":true,"schema":{"type":"string","title":"Subscription Id"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RefundRequest","default":{}}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RefundResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/numbers":{"get":{"tags":["admin"],"summary":"Admin List Numbers","description":"Numbers provisioned per tenant — pagination + search (M7, scalable).\n\nOne number per tenant (WP1b §3); read cross-tenant from subscriptions.","operationId":"admin_list_numbers_api_admin_numbers_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":"integer","maximum":200,"minimum":1,"default":50,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"default":0,"title":"Offset"}},{"name":"q","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Search by phone number (substring)","title":"Q"},"description":"Search by phone number (substring)"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NumberListResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/numbers/{subscription_id}/release":{"post":{"tags":["admin"],"summary":"Admin Release Number","description":"Release the Twilio number bound to a subscription (M7, audited).\n\nReleases the number in Twilio (best-effort; mocked in tests — NO real vendor\ncall here in the unit suite) and clears provisioned_number/_sid locally so a\nfuture provisioning can buy a fresh one (idempotency lives on that field).\n'number.release' is written to the append-only audit log.","operationId":"admin_release_number_api_admin_numbers__subscription_id__release_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"subscription_id","in":"path","required":true,"schema":{"type":"string","title":"Subscription Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NumberActionResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/referrals":{"get":{"tags":["admin"],"summary":"Admin List Referrals","description":"Who referred whom + credit status — pagination (M12).\n\nReads referral_redemptions (referrer -> redeemed user + credit flags). Server-\nside pagination so it stays readable at hundreds of referrals.","operationId":"admin_list_referrals_api_admin_referrals_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":"integer","maximum":200,"minimum":1,"default":50,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"default":0,"title":"Offset"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReferralListResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/referrals/{redeemed_user_id}/revoke":{"post":{"tags":["admin"],"summary":"Admin Revoke Referral Credit","description":"Revoke (cancel) a referral credit for abuse / fraud (M12, audited).\n\nMarks the redemption as NOT credited and NOT pending so no $50 credit is owed\nor paid for it. 'referral.revoke' is written to the audit log.","operationId":"admin_revoke_referral_credit_api_admin_referrals__redeemed_user_id__revoke_post","security":[{"HTTPBearer":[]}],"parameters":[{"name":"redeemed_user_id","in":"path","required":true,"schema":{"type":"string","title":"Redeemed User Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReferralActionResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/conversations":{"get":{"tags":["admin"],"summary":"Admin List Conversations","description":"Cross-tenant conversations with PII MASKED by default (M9, §2.8).\n\nUnlike the public owner-scoped GET /api/conversations (untouched, WP7a), this\nsees every tenant — but phone/name/summary are masked. Full transcript only via\nthe per-id reveal endpoint, which is audited. Server-side pagination + filters.","operationId":"admin_list_conversations_api_admin_conversations_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":"integer","maximum":200,"minimum":1,"default":50,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"default":0,"title":"Offset"}},{"name":"q","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Search by agent_id / status / source (substring)","title":"Q"},"description":"Search by agent_id / status / source (substring)"},{"name":"agent_id","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Filter by agent_id","title":"Agent Id"},"description":"Filter by agent_id"},{"name":"status","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Filter by conversation status","title":"Status"},"description":"Filter by conversation status"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationListResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/conversations/{conversation_id}":{"get":{"tags":["admin"],"summary":"Admin Get Conversation","description":"Conversation detail; PII masked unless reveal=true (M9, §2.8).\n\nreveal=true returns the un-masked phone/name/transcript AND writes\n'conversation.reveal' to the audit log (RODO expects a log of the READ, not\nonly mutations — who revealed whose conversation). Default (reveal=false) keeps\neverything masked and writes NO audit entry.","operationId":"admin_get_conversation_api_admin_conversations__conversation_id__get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"conversation_id","in":"path","required":true,"schema":{"type":"string","title":"Conversation Id"}},{"name":"reveal","in":"query","required":false,"schema":{"type":"boolean","description":"Reveal full PII/transcript (AUDITED)","default":false,"title":"Reveal"},"description":"Reveal full PII/transcript (AUDITED)"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConversationDetailResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/health":{"get":{"tags":["admin"],"summary":"Admin Health","description":"System + vendor health (M10).\n\nLightweight checks: DB (a trivial query), Redis (ping if connected), and whether\neach vendor key (ElevenLabs / Twilio / Stripe) is configured. Plus aggregate\nmetrics (users / active subscriptions / conversations today) — aggregated, never\nper-record. Never raises: a failed probe becomes a 'down' status, not a 500.","operationId":"admin_health_api_admin_health_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/admin/feature-flags":{"get":{"tags":["admin"],"summary":"Admin Get Feature Flags","description":"Current feature flags: global defaults + per-tenant overrides (M8, §3.6).","operationId":"admin_get_feature_flags_api_admin_feature_flags_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FeatureFlagsResponse"}}}}},"security":[{"HTTPBearer":[]}]},"put":{"tags":["admin"],"summary":"Admin Set Feature Flag","description":"Set a feature flag globally or override it for one tenant (M8, audited).\n\naccount_id=None -> set the GLOBAL default. account_id set -> per-tenant override\n(resolves tenant > global). 'feature_flag.update' is written to the audit log.","operationId":"admin_set_feature_flag_api_admin_feature_flags_put","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FeatureFlagUpdate"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FeatureFlagsResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/admin/mfa/enroll":{"post":{"tags":["admin"],"summary":"Admin Mfa Enroll","description":"Begin TOTP enrollment: generate a secret + otpauth URI (M1, §2.5, audited).\n\nStores the secret but does NOT enable MFA yet — the admin must confirm a code\nvia /mfa/verify first (so a broken authenticator can't lock them out). The\notpauth URI is what the authenticator app / QR consumes. 'admin.mfa.enroll' is\nwritten to the audit log.\n\nRe-enroll guard (§2.5): if MFA is ALREADY enabled, replacing the secret would\nsilently DISABLE the existing factor (set_user_mfa_secret resets mfa_enabled=0).\nSo a re-enroll requires a valid CURRENT TOTP code (proof the admin still holds the\nlive authenticator) — never a silent reset/lockout. First-time enrollment (MFA\nnot yet enabled) needs no code.","operationId":"admin_mfa_enroll_api_admin_mfa_enroll_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MfaEnrollRequest","default":{}}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MfaEnrollResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/admin/mfa/verify":{"post":{"tags":["admin"],"summary":"Admin Mfa Verify","description":"Confirm the first TOTP code and ENABLE MFA (M1, §2.5, audited).\n\nVerifies `code` against the secret stored at enroll. On success sets\nmfa_enabled=1 so subsequent admin logins require a TOTP code. 'admin.mfa.verify'\nis written to the audit log.","operationId":"admin_mfa_verify_api_admin_mfa_verify_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MfaVerifyRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MfaVerifyResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}},"security":[{"HTTPBearer":[]}]}},"/api/admin/leads":{"get":{"tags":["admin"],"summary":"Admin List Leads","description":"List captured landing-page email leads — server-side pagination + status filter.\n\nRead-only. Source for the future leads MCP (which reaches this over HTTPS with an\nadmin bearer, NOT the internal-only prod Postgres). Newest first.","operationId":"admin_list_leads_api_admin_leads_get","security":[{"HTTPBearer":[]}],"parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":"integer","maximum":200,"minimum":1,"default":50,"title":"Limit"}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"default":0,"title":"Offset"}},{"name":"status","in":"query","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Filter by lead status (e.g. new)","title":"Status"},"description":"Filter by lead status (e.g. new)"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LeadListResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/admin/leads/stats":{"get":{"tags":["admin"],"summary":"Admin Lead Stats","description":"Aggregate landing-lead counts: total, new (status='new'), last_7d, with_phone\n(callback-intent leads). Read-only.","operationId":"admin_lead_stats_api_admin_leads_stats_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LeadStatsResponse"}}}}},"security":[{"HTTPBearer":[]}]}},"/privacy":{"get":{"tags":["legal"],"summary":"Privacy Policy","description":"Public Privacy Policy (no auth).","operationId":"privacy_policy_privacy_get","responses":{"200":{"description":"Successful Response","content":{"text/html":{"schema":{"type":"string"}}}}}}},"/terms":{"get":{"tags":["legal"],"summary":"Terms Of Service","description":"Public Terms of Service (no auth).","operationId":"terms_of_service_terms_get","responses":{"200":{"description":"Successful Response","content":{"text/html":{"schema":{"type":"string"}}}}}}},"/dpa":{"get":{"tags":["legal"],"summary":"Data Processing Agreement","description":"Public Data Processing Agreement / Addendum (no auth).\n\nController-processor (business / service-provider) contract required by U.S.\nstate privacy laws (CCPA, VCDPA, CPA, CTDPA, ...). Incorporated by reference\ninto the Terms and accepted at onboarding alongside the Terms & Privacy Policy.","operationId":"data_processing_agreement_dpa_get","responses":{"200":{"description":"Successful Response","content":{"text/html":{"schema":{"type":"string"}}}}}}},"/biometric":{"get":{"tags":["legal"],"summary":"Biometric Policy","description":"Public Biometric Data Policy (no auth).\n\nStates the no-voiceprint posture (BIPA/CUBI): transcription + diarization\ncreate no biometric identifier; recognised-caller matching uses phone/CRM\ndata, not voice. Supplements the Privacy Policy.","operationId":"biometric_policy_biometric_get","responses":{"200":{"description":"Successful Response","content":{"text/html":{"schema":{"type":"string"}}}}}}},"/internal/usage/check-permission":{"post":{"tags":["internal-brain"],"summary":"Internal Check Permission","description":"Sprawdza limit połączeń dla agenta.","operationId":"internal_check_permission_internal_usage_check_permission_post","parameters":[{"name":"X-Internal-Secret","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"X-Internal-Secret"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UsageCheckRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/internal/usage/add":{"post":{"tags":["internal-brain"],"summary":"Internal Add Usage","description":"Nalicza zużycie minut po połączeniu.","operationId":"internal_add_usage_internal_usage_add_post","parameters":[{"name":"X-Internal-Secret","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"X-Internal-Secret"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UsageAddRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/internal/usage/resolve-user":{"post":{"tags":["internal-brain"],"summary":"Internal Resolve User","description":"Mapuje agent_id -> user_id (właściciel agenta) czytając agent DB.\n\nBrain JEST jedynym właścicielem `brain-db` (named volume montowany tylko w Brain),\nwięc lookup agent->user MUSI iść tędy. Voice woła to po post-call (metering) zamiast\nczytać własną, image-baked, nieaktualną kopię agent_creator.db. Zwraca {\"user_id\": None}\ndla nieznanego/niezmapowanego agenta (np. agent skasowany) — bez błędu.","operationId":"internal_resolve_user_internal_usage_resolve_user_post","parameters":[{"name":"X-Internal-Secret","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"X-Internal-Secret"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UsageCheckRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/internal/agent/create-workflow":{"post":{"tags":["internal-brain"],"summary":"Internal Create Agent Workflow","description":"Uruchamia workflow tworzenia agenta w tle.\n\nONBOARDING->LOGIN BRIDGE (start mark): BEFORE the workflow is spawned, the\npending_agents row is flipped (back) to 'in_progress' so GET /api/auth/account-status\nreads 'processing' for the entire run. Critical for RE-TRIGGERED workflows: a prior\nrun leaves the row terminal-'failed' and the Voice-side early write deliberately\nrefuses to resurrect terminal rows, so without this flip the app said \"no account\"\nduring the whole re-run (2026-06-11 incident, conv_0201ktvas2...). Every dispatch —\nfirst run and re-trigger alike — goes through THIS endpoint, so the mark lives here.\nBest-effort: a bridge write must never block provisioning. 'agent_created' is never\ndowngraded (guard inside mark_pending_in_flight).","operationId":"internal_create_agent_workflow_internal_agent_create_workflow_post","parameters":[{"name":"X-Internal-Secret","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"X-Internal-Secret"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentWorkflowRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/internal/appointment/from-collected":{"post":{"tags":["internal-brain"],"summary":"Internal Appointment From Collected","description":"Tworzy wizytę z collected_data (polish date parser).","operationId":"internal_appointment_from_collected_internal_appointment_from_collected_post","parameters":[{"name":"X-Internal-Secret","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"X-Internal-Secret"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppointmentFromCollectedRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"AdminDashboard":{"properties":{"total_workers":{"type":"integer","title":"Total Workers"},"active_workers":{"type":"integer","title":"Active Workers"},"total_leads":{"type":"integer","title":"Total Leads"},"leads_this_month":{"type":"integer","title":"Leads This Month"},"total_paying_clients":{"type":"integer","title":"Total Paying Clients"},"revenue_this_month":{"type":"number","title":"Revenue This Month"},"revenue_total":{"type":"number","title":"Revenue Total"},"avg_conversion_rate":{"type":"number","title":"Avg Conversion Rate"},"top_workers":{"items":{"$ref":"#/components/schemas/WorkerSummary"},"type":"array","title":"Top Workers"}},"type":"object","required":["total_workers","active_workers","total_leads","leads_this_month","total_paying_clients","revenue_this_month","revenue_total","avg_conversion_rate","top_workers"],"title":"AdminDashboard"},"AdminSettingsResponse":{"properties":{"base_agent_llm_model":{"type":"string","title":"Base Agent Llm Model"},"favorite_llm_models":{"items":{"type":"string"},"type":"array","title":"Favorite Llm Models","default":[]},"available_models":{"items":{"type":"string"},"type":"array","title":"Available Models","default":[]},"available_models_source":{"type":"string","title":"Available Models Source","default":"curated"},"billing_mode":{"type":"string","title":"Billing Mode","default":"test"}},"type":"object","required":["base_agent_llm_model"],"title":"AdminSettingsResponse"},"AdminSettingsUpdate":{"properties":{"base_agent_llm_model":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Base Agent Llm Model","description":"Global default LLM model for newly created agents (§11)"},"favorite_llm_models":{"anyOf":[{"items":{"type":"string"},"type":"array"},{"type":"null"}],"title":"Favorite Llm Models","description":"Admin shortlist of favorite models (§11)"}},"type":"object","title":"AdminSettingsUpdate"},"AgentConfigResponse":{"properties":{"agent_id":{"type":"string","title":"Agent Id"},"name":{"type":"string","title":"Name"},"voice_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Voice Id"},"voice_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Voice Name"},"first_message":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"First Message"},"speed":{"type":"number","title":"Speed","default":1.0},"stability":{"type":"number","title":"Stability","default":0.5},"similarity_boost":{"type":"number","title":"Similarity Boost","default":0.75},"tts_model_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Tts Model Id"},"speed_supported":{"type":"boolean","title":"Speed Supported","default":true},"turn_eagerness":{"type":"string","title":"Turn Eagerness","default":"normal"},"llm_model":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Llm Model"},"role":{"type":"string","title":"Role","default":"main"},"parsed_fields":{"$ref":"#/components/schemas/ParsedFields"},"editable_prompt":{"type":"string","title":"Editable Prompt","default":""},"vertical":{"type":"string","title":"Vertical","default":"generic"},"collect_fields":{"items":{"$ref":"#/components/schemas/CollectFieldOut"},"type":"array","title":"Collect Fields","default":[]},"max_call_seconds":{"type":"integer","title":"Max Call Seconds","default":420},"announce_before_end":{"type":"boolean","title":"Announce Before End","default":true},"max_call_seconds_min":{"type":"integer","title":"Max Call Seconds Min","default":120},"max_call_seconds_max":{"type":"integer","title":"Max Call Seconds Max","default":900},"greeting_mode":{"type":"string","title":"Greeting Mode","default":"custom"},"base_greeting":{"type":"string","title":"Base Greeting","default":""}},"type":"object","required":["agent_id","name","parsed_fields"],"title":"AgentConfigResponse","description":"Pelna konfiguracja agenta"},"AgentInfo":{"properties":{"agent_id":{"type":"string","title":"Agent Id"},"business_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Business Name"},"business_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Business Type"},"assigned_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Assigned Phone"},"status":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status"}},"type":"object","required":["agent_id"],"title":"AgentInfo"},"AgentListItem":{"properties":{"agent_id":{"type":"string","title":"Agent Id"},"name":{"type":"string","title":"Name"},"business_name":{"type":"string","title":"Business Name"},"business_type":{"type":"string","title":"Business Type"},"status":{"type":"string","title":"Status"},"assigned_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Assigned Phone"},"voice_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Voice Name"},"role":{"type":"string","title":"Role","default":"main"},"is_router":{"type":"boolean","title":"Is Router","default":false}},"type":"object","required":["agent_id","name","business_name","business_type","status"],"title":"AgentListItem","description":"Agent na liscie.\n\n`role`/`is_router` let the client collapse the N sub-agents of one business into a\nsingle logical receptionist card. The business may own a multi-agent topology\n(1 router/main + booking/info/... specialists); the UI picks ONE canonical row\n(a non-router) and routes the edit there, while shared edits fan out server-side."},"AgentUpdateRequest":{"properties":{"voice_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Voice Id","description":"ID glosu z listy dozwolonych"},"first_message":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"First Message","description":"Tekst powitania"},"faq":{"anyOf":[{"items":{"$ref":"#/components/schemas/FAQItem"},"type":"array"},{"type":"null"}],"title":"Faq","description":"Lista FAQ"},"questions":{"anyOf":[{"items":{"$ref":"#/components/schemas/QuestionItem"},"type":"array"},{"type":"null"}],"title":"Questions","description":"DEPRECATED back-compat alias. Nowe UI uzywa collect_fields. Pytania do zbierania [{field, prompt}]."},"collect_fields":{"anyOf":[{"items":{"$ref":"#/components/schemas/CollectFieldIn"},"type":"array"},{"type":"null"}],"title":"Collect Fields","description":"Per-vertical collect toggle/wording. Gdy obecne, ZASTEPUJE stan collect. Tylko reserved registry-keys TEGO verticalu sa akceptowane; reszta dropped."},"speed":{"anyOf":[{"type":"number","maximum":1.2,"minimum":0.7},{"type":"null"}],"title":"Speed","description":"Szybkosc mowienia 0.7-1.2"},"eagerness":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Eagerness","description":"Styl: patient|normal|eager"},"prompt_text":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Prompt Text","description":"Pelny prompt (tryb zaawansowany)"},"goodbye":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Goodbye","description":"Tekst pozegnania"},"persona_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Persona Name","description":"Imie agenta/agentki (slychac w rozmowie, podmieniane w prompcie)"},"business_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Business Name","description":"Nazwa firmy (podmieniana w prompcie)"},"working_hours":{"anyOf":[{"$ref":"#/components/schemas/WorkingHours"},{"type":"null"}],"description":"Godziny pracy"},"llm_model":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Llm Model","description":"Model LLM agenta (§11B, live PATCH prompt.llm)"},"max_call_seconds":{"anyOf":[{"type":"integer","maximum":900.0,"minimum":120.0},{"type":"null"}],"title":"Max Call Seconds","description":"Maksymalny czas rozmowy w SEKUNDACH (120-900). None => bez zmiany."},"announce_before_end":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Announce Before End","description":"Czy recepcjonista wypowiada neutralny komunikat przed rozlaczeniem. None => bez zmiany."},"greeting_mode":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Greeting Mode","description":"'custom' = owner-edited greeting in effect; 'base' = the original onboarding (Mia-generated) greeting in effect. None => no change."},"apply":{"type":"string","title":"Apply","description":"'this' (default) edits only this agent; 'shared' fans SHARED fields out to all sub-agents of the same business (prompt_text stays scoped).","default":"this"}},"type":"object","title":"AgentUpdateRequest","description":"Request aktualizacji agenta"},"AgentWorkflowRequest":{"properties":{"transcript":{"type":"string","title":"Transcript"},"customer_phone":{"type":"string","title":"Customer Phone"},"conversation_id":{"type":"string","title":"Conversation Id"},"agent_phone_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Phone Number"},"v1_data":{"additionalProperties":true,"type":"object","title":"V1 Data"}},"type":"object","required":["transcript","customer_phone","conversation_id","v1_data"],"title":"AgentWorkflowRequest"},"AppointmentCreate":{"properties":{"title":{"type":"string","title":"Title"},"description":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Description"},"date_time":{"type":"string","title":"Date Time"},"duration":{"type":"integer","title":"Duration","default":60},"client_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Phone"},"client_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Name"},"conversation_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Conversation Id"},"reminder":{"type":"boolean","title":"Reminder","default":true},"agent_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Id"}},"type":"object","required":["title","date_time"],"title":"AppointmentCreate"},"AppointmentFromCollectedRequest":{"properties":{"collected_data":{"additionalProperties":true,"type":"object","title":"Collected Data"},"conversation_id":{"type":"string","title":"Conversation Id"},"agent_id":{"type":"string","title":"Agent Id"},"caller_phone":{"type":"string","title":"Caller Phone"}},"type":"object","required":["collected_data","conversation_id","agent_id","caller_phone"],"title":"AppointmentFromCollectedRequest"},"AuditLogEntry":{"properties":{"id":{"type":"integer","title":"Id"},"ts":{"type":"string","title":"Ts"},"actor_user_id":{"type":"string","title":"Actor User Id"},"actor_role":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Actor Role"},"action":{"type":"string","title":"Action"},"target_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Target Type"},"target_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Target Id"},"detail":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Detail"},"ip":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Ip"}},"type":"object","required":["id","ts","actor_user_id","action"],"title":"AuditLogEntry"},"AuditLogResponse":{"properties":{"entries":{"items":{"$ref":"#/components/schemas/AuditLogEntry"},"type":"array","title":"Entries"},"total":{"type":"integer","title":"Total"},"limit":{"type":"integer","title":"Limit"},"offset":{"type":"integer","title":"Offset"}},"type":"object","required":["entries","total","limit","offset"],"title":"AuditLogResponse"},"AvailabilityRequest":{"properties":{"agent_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Id"},"date":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Date"},"time":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Time"},"caller_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Caller Phone"}},"type":"object","title":"AvailabilityRequest"},"BookRequest":{"properties":{"agent_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Id"},"date":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Date"},"time":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Time"},"customer_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Customer Name"},"service_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Service Type"},"caller_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Caller Phone"},"conversation_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Conversation Id"}},"additionalProperties":true,"type":"object","title":"BookRequest","description":"Body of the shared `book_appointment` EL webhook tool. {{system__agent_id}}\nand {{system__conversation_id}} are bound in the registered tool body; the\nagent supplies date/time/customer_name/service_type (+ vertical fields like\npet_name, which ride along via extra=allow and land in the description)."},"BuyMinutesRequest":{"properties":{"minutes":{"type":"integer","title":"Minutes"},"success_url":{"type":"string","title":"Success Url"},"cancel_url":{"type":"string","title":"Cancel Url"}},"type":"object","required":["minutes","success_url","cancel_url"],"title":"BuyMinutesRequest"},"CancelRequest":{"properties":{"agent_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Id"},"caller_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Caller Phone"},"date":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Date"},"time":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Time"}},"additionalProperties":true,"type":"object","title":"CancelRequest","description":"Body of the `cancel_my_appointment` tool. agent_id/caller_phone are EL-injected;\ndate/time are LLM-OPTIONAL disambiguators when the caller has >1 upcoming booking."},"CancelSubscriptionRequest":{"properties":{"reason":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Reason"}},"type":"object","title":"CancelSubscriptionRequest"},"ChangePlanRequest":{"properties":{"plan_id":{"type":"string","title":"Plan Id"},"proration_date":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Proration Date"}},"type":"object","required":["plan_id"],"title":"ChangePlanRequest"},"CollectFieldIn":{"properties":{"key":{"type":"string","title":"Key","description":"Reserved registry fixed_key TEGO verticalu."},"enabled":{"type":"boolean","title":"Enabled","description":"On/off toggle.","default":true},"question":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Question","description":"Reworded ASK; null => domyslne pytanie."}},"type":"object","required":["key"],"title":"CollectFieldIn","description":"Jedno per-vertical pole do zebrania (request). Tylko `enabled` i `question` sa\nwritable; `key` MUSI byc reserved registry-key TEGO verticalu (server-side guard),\na wszelkie client-sent label sa ignorowane."},"CollectFieldOut":{"properties":{"key":{"type":"string","title":"Key","description":"Immutable FieldDef.fixed_key (LOWER_SNAKE). READ-ONLY."},"label":{"type":"string","title":"Label","description":"Plain English label pokazywany w UI (NIE raw key)."},"enabled":{"type":"boolean","title":"Enabled","description":"Aktualny toggle (default-on chyba ze owner wylaczyl).","default":true},"question":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Question","description":"Owner-reworded ASK; null => domyslne pytanie."}},"type":"object","required":["key","label"],"title":"CollectFieldOut","description":"Jedno per-vertical pole do zebrania (response). `key`/`label` sa server-owned\n(read-only dla klienta); klient renderuje `label`, nigdy raw `key`."},"CommissionResponse":{"properties":{"id":{"type":"string","title":"Id"},"sales_rep_id":{"type":"string","title":"Sales Rep Id"},"lead_id":{"type":"string","title":"Lead Id"},"client_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Phone"},"client_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Name"},"period_month":{"type":"string","title":"Period Month"},"amount_pln":{"type":"number","title":"Amount Pln"},"rate_used":{"type":"number","title":"Rate Used"},"status":{"type":"string","title":"Status"},"paid_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Paid At"}},"type":"object","required":["id","sales_rep_id","lead_id","period_month","amount_pln","rate_used","status"],"title":"CommissionResponse"},"ConversationCreate":{"properties":{"id":{"type":"string","title":"Id"},"client_phone":{"type":"string","title":"Client Phone"},"client_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Name"},"transcription":{"type":"string","title":"Transcription"},"summary":{"type":"string","title":"Summary"},"duration":{"type":"integer","title":"Duration"},"created_at":{"type":"string","title":"Created At"},"status":{"type":"string","title":"Status","default":"new"},"source":{"type":"string","title":"Source","default":"passthrough"},"collected_data":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Collected Data"},"agent_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Id"},"cost_data":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Cost Data"},"is_emergency":{"type":"boolean","title":"Is Emergency","default":false},"call_channel":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Call Channel"}},"type":"object","required":["id","client_phone","transcription","summary","duration","created_at"],"title":"ConversationCreate","description":"Model do tworzenia rozmowy przez API (z V4 backend)."},"ConversationDetailResponse":{"properties":{"id":{"type":"string","title":"Id"},"agent_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Id"},"client_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Phone"},"client_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Name"},"transcription":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Transcription"},"summary":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Summary"},"duration":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Duration"},"status":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status"},"source":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Source"},"created_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Created At"},"pii_masked":{"type":"boolean","title":"Pii Masked","default":true}},"type":"object","required":["id"],"title":"ConversationDetailResponse"},"ConversationListItem":{"properties":{"id":{"type":"string","title":"Id"},"agent_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Id"},"client_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Phone"},"client_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Name"},"summary":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Summary"},"duration":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Duration"},"status":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Status"},"source":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Source"},"created_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Created At"},"pii_masked":{"type":"boolean","title":"Pii Masked","default":true}},"type":"object","required":["id"],"title":"ConversationListItem"},"ConversationListResponse":{"properties":{"conversations":{"items":{"$ref":"#/components/schemas/ConversationListItem"},"type":"array","title":"Conversations"},"total":{"type":"integer","title":"Total"},"limit":{"type":"integer","title":"Limit"},"offset":{"type":"integer","title":"Offset"},"pii_masked":{"type":"boolean","title":"Pii Masked","default":true}},"type":"object","required":["conversations","total","limit","offset"],"title":"ConversationListResponse"},"CostSummaryResponse":{"properties":{"range":{"additionalProperties":{"anyOf":[{"type":"string"},{"type":"null"}]},"type":"object","title":"Range"},"call_count":{"type":"integer","title":"Call Count"},"by_provider":{"additionalProperties":{"type":"number"},"type":"object","title":"By Provider"},"cogs_usd":{"type":"number","title":"Cogs Usd"},"revenue_usd":{"type":"number","title":"Revenue Usd"},"margin_usd":{"type":"number","title":"Margin Usd"},"margin_pct":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Margin Pct"},"total_minutes":{"type":"number","title":"Total Minutes"},"active_subscriptions":{"type":"integer","title":"Active Subscriptions"},"top_agents":{"items":{"additionalProperties":true,"type":"object"},"type":"array","title":"Top Agents","default":[]}},"type":"object","required":["range","call_count","by_provider","cogs_usd","revenue_usd","margin_usd","total_minutes","active_subscriptions"],"title":"CostSummaryResponse"},"CreateCheckoutRequest":{"properties":{"success_url":{"type":"string","title":"Success Url"},"cancel_url":{"type":"string","title":"Cancel Url"},"plan_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Plan Id","default":"pro"}},"type":"object","required":["success_url","cancel_url"],"title":"CreateCheckoutRequest"},"CreateWorkerRequest":{"properties":{"name":{"type":"string","title":"Name"},"phone":{"type":"string","title":"Phone"},"email":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Email"},"password":{"type":"string","minLength":6,"title":"Password"},"commission_rate_first_3m":{"type":"number","title":"Commission Rate First 3M","default":0.5},"commission_rate_after":{"type":"number","title":"Commission Rate After","default":0.1}},"type":"object","required":["name","phone","password"],"title":"CreateWorkerRequest"},"DemoRequest":{"properties":{"name":{"type":"string","title":"Name"},"phone":{"type":"string","title":"Phone"},"business_type":{"type":"string","title":"Business Type","default":""},"honeypot":{"type":"string","title":"Honeypot","default":""}},"type":"object","required":["name","phone"],"title":"DemoRequest"},"DeviceRegister":{"properties":{"token":{"type":"string","title":"Token","description":"Expo push token, np. ExponentPushToken[xxxxx]"},"platform":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Platform","description":"ios | android"}},"type":"object","required":["token"],"title":"DeviceRegister"},"DeviceUnregister":{"properties":{"token":{"type":"string","title":"Token"}},"type":"object","required":["token"],"title":"DeviceUnregister"},"EarningsSummary":{"properties":{"available_pln":{"type":"number","title":"Available Pln"},"pending_pln":{"type":"number","title":"Pending Pln"},"paid_total_pln":{"type":"number","title":"Paid Total Pln"},"this_month_pln":{"type":"number","title":"This Month Pln"}},"type":"object","required":["available_pln","pending_pln","paid_total_pln","this_month_pln"],"title":"EarningsSummary"},"FAQItem":{"properties":{"question":{"type":"string","minLength":1,"title":"Question","description":"Pytanie klienta"},"answer":{"type":"string","minLength":1,"title":"Answer","description":"Odpowiedz agenta"}},"type":"object","required":["question","answer"],"title":"FAQItem","description":"Pojedyncze pytanie i odpowiedz FAQ"},"FeatureFlagUpdate":{"properties":{"key":{"type":"string","title":"Key"},"enabled":{"type":"boolean","title":"Enabled"},"account_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Account Id"}},"type":"object","required":["key","enabled"],"title":"FeatureFlagUpdate"},"FeatureFlagsResponse":{"properties":{"flags":{"additionalProperties":{"type":"boolean"},"type":"object","title":"Flags"},"overrides":{"additionalProperties":{"additionalProperties":{"type":"boolean"},"type":"object"},"type":"object","title":"Overrides","default":{}}},"type":"object","required":["flags"],"title":"FeatureFlagsResponse"},"ForgotBody":{"properties":{"email_or_phone":{"type":"string","title":"Email Or Phone"}},"type":"object","required":["email_or_phone"],"title":"ForgotBody"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"HealthResponse":{"properties":{"status":{"type":"string","title":"Status"},"services":{"additionalProperties":{"type":"string"},"type":"object","title":"Services"},"vendors":{"items":{"$ref":"#/components/schemas/VendorStatus"},"type":"array","title":"Vendors"},"metrics":{"additionalProperties":{"type":"integer"},"type":"object","title":"Metrics"}},"type":"object","required":["status","services","vendors","metrics"],"title":"HealthResponse"},"ImpersonateResponse":{"properties":{"access_token":{"type":"string","title":"Access Token"},"token_type":{"type":"string","title":"Token Type","default":"bearer"},"expires_in":{"type":"integer","title":"Expires In"},"impersonated_user_id":{"type":"string","title":"Impersonated User Id"},"impersonated_by":{"type":"string","title":"Impersonated By"}},"type":"object","required":["access_token","expires_in","impersonated_user_id","impersonated_by"],"title":"ImpersonateResponse"},"LeadCreate":{"properties":{"client_phone":{"type":"string","title":"Client Phone"},"client_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Name"},"client_business_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Business Type"},"source":{"$ref":"#/components/schemas/LeadSource","default":"cold_call"},"notes":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Notes"}},"type":"object","required":["client_phone"],"title":"LeadCreate"},"LeadListItem":{"properties":{"id":{"type":"string","title":"Id"},"email":{"type":"string","title":"Email"},"source":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Source"},"path":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Path"},"ip":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Ip"},"user_agent":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"User Agent"},"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name"},"phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Phone"},"preferred_time":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Preferred Time"},"preferred_tz":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Preferred Tz"},"preferred_time_founder":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Preferred Time Founder"},"status":{"type":"string","title":"Status","default":"new"},"created_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Created At"}},"type":"object","required":["id","email"],"title":"LeadListItem"},"LeadListResponse":{"properties":{"leads":{"items":{"$ref":"#/components/schemas/LeadListItem"},"type":"array","title":"Leads"},"total":{"type":"integer","title":"Total"},"limit":{"type":"integer","title":"Limit"},"offset":{"type":"integer","title":"Offset"}},"type":"object","required":["leads","total","limit","offset"],"title":"LeadListResponse"},"LeadRequest":{"properties":{"email":{"type":"string","title":"Email","default":""},"source":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Source"},"path":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Path"},"hp":{"type":"string","title":"Hp","default":""},"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name"},"phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Phone"},"preferred_time":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Preferred Time"},"timezone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Timezone"}},"type":"object","title":"LeadRequest"},"LeadResponse":{"properties":{"id":{"type":"string","title":"Id"},"sales_rep_id":{"type":"string","title":"Sales Rep Id"},"sales_rep_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Sales Rep Name"},"client_phone":{"type":"string","title":"Client Phone"},"client_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Name"},"client_business_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Business Type"},"source":{"type":"string","title":"Source"},"status":{"type":"string","title":"Status"},"notes":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Notes"},"created_at":{"type":"string","title":"Created At"},"demo_called_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Demo Called At"},"trial_started_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Trial Started At"},"first_payment_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"First Payment At"},"churned_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Churned At"}},"type":"object","required":["id","sales_rep_id","client_phone","source","status","created_at"],"title":"LeadResponse"},"LeadSource":{"type":"string","enum":["cold_call","visit","own_method"],"title":"LeadSource"},"LeadStatsResponse":{"properties":{"total":{"type":"integer","title":"Total"},"new":{"type":"integer","title":"New"},"last_7d":{"type":"integer","title":"Last 7D"},"with_phone":{"type":"integer","title":"With Phone","default":0}},"type":"object","required":["total","new","last_7d"],"title":"LeadStatsResponse"},"LeadStatus":{"type":"string","enum":["entered","demo_called","trial_active","paid","churned"],"title":"LeadStatus"},"LeadUpdate":{"properties":{"client_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Name"},"client_business_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Client Business Type"},"status":{"anyOf":[{"$ref":"#/components/schemas/LeadStatus"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Notes"}},"type":"object","title":"LeadUpdate"},"LlmModelsResponse":{"properties":{"models":{"items":{"type":"string"},"type":"array","title":"Models"},"source":{"type":"string","title":"Source"},"favorites":{"items":{"type":"string"},"type":"array","title":"Favorites","default":[]},"base_model":{"type":"string","title":"Base Model"},"default":{"type":"string","title":"Default"}},"type":"object","required":["models","source","base_model","default"],"title":"LlmModelsResponse"},"LoginRequest":{"properties":{"phone":{"type":"string","title":"Phone"},"password":{"type":"string","title":"Password"},"totp_code":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Totp Code"}},"type":"object","required":["phone","password"],"title":"LoginRequest"},"LoginTokenBody":{"properties":{"token":{"type":"string","title":"Token"}},"type":"object","required":["token"],"title":"LoginTokenBody"},"MfaEnrollRequest":{"properties":{"current_code":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Current Code"}},"type":"object","title":"MfaEnrollRequest"},"MfaEnrollResponse":{"properties":{"secret":{"type":"string","title":"Secret"},"otpauth_uri":{"type":"string","title":"Otpauth Uri"},"issuer":{"type":"string","title":"Issuer"}},"type":"object","required":["secret","otpauth_uri","issuer"],"title":"MfaEnrollResponse"},"MfaVerifyRequest":{"properties":{"code":{"type":"string","title":"Code"}},"type":"object","required":["code"],"title":"MfaVerifyRequest"},"MfaVerifyResponse":{"properties":{"success":{"type":"boolean","title":"Success"},"mfa_enabled":{"type":"boolean","title":"Mfa Enabled"}},"type":"object","required":["success","mfa_enabled"],"title":"MfaVerifyResponse"},"MyAppointmentsRequest":{"properties":{"agent_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Id"},"caller_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Caller Phone"}},"additionalProperties":true,"type":"object","title":"MyAppointmentsRequest","description":"Body of the `list_my_appointments` tool. Both fields are EL-injected dynamic vars\n(the LLM cannot supply/forge the phone)."},"NumberActionResponse":{"properties":{"success":{"type":"boolean","title":"Success"},"subscription_id":{"type":"string","title":"Subscription Id"},"released_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Released Number"},"released_sid":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Released Sid"}},"type":"object","required":["success","subscription_id"],"title":"NumberActionResponse"},"NumberListItem":{"properties":{"subscription_id":{"type":"string","title":"Subscription Id"},"user_id":{"type":"string","title":"User Id"},"plan":{"type":"string","title":"Plan"},"status":{"type":"string","title":"Status"},"phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Phone"},"number_sid":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Number Sid"}},"type":"object","required":["subscription_id","user_id","plan","status"],"title":"NumberListItem"},"NumberListResponse":{"properties":{"numbers":{"items":{"$ref":"#/components/schemas/NumberListItem"},"type":"array","title":"Numbers"},"total":{"type":"integer","title":"Total"},"limit":{"type":"integer","title":"Limit"},"offset":{"type":"integer","title":"Offset"}},"type":"object","required":["numbers","total","limit","offset"],"title":"NumberListResponse"},"ParsedFields":{"properties":{"persona_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Persona Name"},"business_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Business Name"},"role_description":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Role Description"},"is_router":{"type":"boolean","title":"Is Router","default":false},"has_protected_sections":{"type":"boolean","title":"Has Protected Sections","default":false},"faq":{"items":{"$ref":"#/components/schemas/FAQItem"},"type":"array","title":"Faq","default":[]},"questions":{"items":{"$ref":"#/components/schemas/QuestionItem"},"type":"array","title":"Questions","default":[]},"goodbye_message":{"type":"string","title":"Goodbye Message","default":"Dziekujemy! Do uslyszenia!"},"working_hours":{"anyOf":[{"$ref":"#/components/schemas/WorkingHours"},{"type":"null"}]},"services":{"items":{"type":"string"},"type":"array","title":"Services","default":[]}},"type":"object","title":"ParsedFields","description":"Sparsowane pola z prompta"},"PasswordChangeRequest":{"properties":{"current_password":{"type":"string","title":"Current Password"},"new_password":{"type":"string","title":"New Password"}},"type":"object","required":["current_password","new_password"],"title":"PasswordChangeRequest"},"PaymentListItem":{"properties":{"id":{"type":"string","title":"Id"},"user_id":{"type":"string","title":"User Id"},"subscription_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Subscription Id"},"amount":{"type":"integer","title":"Amount"},"currency":{"type":"string","title":"Currency"},"status":{"type":"string","title":"Status"},"description":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Description"},"created_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Created At"}},"type":"object","required":["id","user_id","amount","currency","status"],"title":"PaymentListItem"},"PaymentListResponse":{"properties":{"payments":{"items":{"$ref":"#/components/schemas/PaymentListItem"},"type":"array","title":"Payments"},"total":{"type":"integer","title":"Total"},"limit":{"type":"integer","title":"Limit"},"offset":{"type":"integer","title":"Offset"}},"type":"object","required":["payments","total","limit","offset"],"title":"PaymentListResponse"},"PayoutAdminUpdate":{"properties":{"status":{"$ref":"#/components/schemas/PayoutStatus"},"notes":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Notes"}},"type":"object","required":["status"],"title":"PayoutAdminUpdate"},"PayoutRequest":{"properties":{"amount_pln":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Amount Pln"}},"type":"object","title":"PayoutRequest"},"PayoutResponse":{"properties":{"id":{"type":"string","title":"Id"},"sales_rep_id":{"type":"string","title":"Sales Rep Id"},"sales_rep_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Sales Rep Name"},"amount_pln":{"type":"number","title":"Amount Pln"},"status":{"type":"string","title":"Status"},"requested_at":{"type":"string","title":"Requested At"},"completed_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Completed At"},"notes":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Notes"}},"type":"object","required":["id","sales_rep_id","amount_pln","status","requested_at"],"title":"PayoutResponse"},"PayoutStatus":{"type":"string","enum":["requested","processing","completed","rejected"],"title":"PayoutStatus"},"PhoneBody":{"properties":{"phone":{"type":"string","title":"Phone"}},"type":"object","required":["phone"],"title":"PhoneBody"},"PhoneSettingsUpdate":{"properties":{"config_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Config Id"},"mode":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Mode"},"dial_timeout":{"anyOf":[{"type":"integer","maximum":120.0,"minimum":3.0},{"type":"null"}],"title":"Dial Timeout"},"passthrough_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Passthrough Number"},"ai_schedule":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Ai Schedule"},"slot_duration_minutes":{"anyOf":[{"type":"integer","maximum":240.0,"minimum":5.0},{"type":"null"}],"title":"Slot Duration Minutes"},"capacity_per_slot":{"anyOf":[{"type":"integer","maximum":10.0,"minimum":1.0},{"type":"null"}],"title":"Capacity Per Slot"},"cancellation_advance_notice_hours":{"anyOf":[{"type":"integer","maximum":168.0,"minimum":0.0},{"type":"null"}],"title":"Cancellation Advance Notice Hours"},"reschedule_advance_notice_hours":{"anyOf":[{"type":"integer","maximum":168.0,"minimum":0.0},{"type":"null"}],"title":"Reschedule Advance Notice Hours"}},"type":"object","title":"PhoneSettingsUpdate"},"PortalRequest":{"properties":{"return_url":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Return Url"}},"type":"object","title":"PortalRequest"},"QuestionItem":{"properties":{"field":{"type":"string","minLength":1,"title":"Field","description":"Nazwa pola do zebrania"},"prompt":{"type":"string","minLength":1,"title":"Prompt","description":"Pytanie do klienta"}},"type":"object","required":["field","prompt"],"title":"QuestionItem","description":"Pytanie do zbierania danych od klienta"},"ReferralActionResponse":{"properties":{"success":{"type":"boolean","title":"Success"},"redeemed_user_id":{"type":"string","title":"Redeemed User Id"},"action":{"type":"string","title":"Action"}},"type":"object","required":["success","redeemed_user_id","action"],"title":"ReferralActionResponse"},"ReferralListItem":{"properties":{"redeemed_user_id":{"type":"string","title":"Redeemed User Id"},"code":{"type":"string","title":"Code"},"referrer_user_id":{"type":"string","title":"Referrer User Id"},"promo_code_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Promo Code Id"},"redeemed_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Redeemed At"},"referrer_credited":{"type":"boolean","title":"Referrer Credited","default":false},"referrer_credit_pending":{"type":"boolean","title":"Referrer Credit Pending","default":false},"credited_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Credited At"}},"type":"object","required":["redeemed_user_id","code","referrer_user_id"],"title":"ReferralListItem"},"ReferralListResponse":{"properties":{"referrals":{"items":{"$ref":"#/components/schemas/ReferralListItem"},"type":"array","title":"Referrals"},"total":{"type":"integer","title":"Total"},"limit":{"type":"integer","title":"Limit"},"offset":{"type":"integer","title":"Offset"}},"type":"object","required":["referrals","total","limit","offset"],"title":"ReferralListResponse"},"RefundRequest":{"properties":{"reason":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Reason"}},"type":"object","title":"RefundRequest"},"RefundResponse":{"properties":{"success":{"type":"boolean","title":"Success"},"payment_id":{"type":"string","title":"Payment Id"},"status":{"type":"string","title":"Status"},"refund_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Refund Id"}},"type":"object","required":["success","payment_id","status"],"title":"RefundResponse"},"RepDashboard":{"properties":{"total_leads":{"type":"integer","title":"Total Leads"},"leads_this_month":{"type":"integer","title":"Leads This Month"},"demo_count":{"type":"integer","title":"Demo Count"},"demo_rate":{"type":"number","title":"Demo Rate"},"trial_count":{"type":"integer","title":"Trial Count"},"trial_rate":{"type":"number","title":"Trial Rate"},"paid_count":{"type":"integer","title":"Paid Count"},"paid_rate":{"type":"number","title":"Paid Rate"},"churned_count":{"type":"integer","title":"Churned Count"},"earnings_this_month":{"type":"number","title":"Earnings This Month"},"earnings_total":{"type":"number","title":"Earnings Total"},"available_payout":{"type":"number","title":"Available Payout"}},"type":"object","required":["total_leads","leads_this_month","demo_count","demo_rate","trial_count","trial_rate","paid_count","paid_rate","churned_count","earnings_this_month","earnings_total","available_payout"],"title":"RepDashboard"},"RescheduleRequest":{"properties":{"agent_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Agent Id"},"caller_phone":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Caller Phone"},"date":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Date"},"time":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Time"},"new_date":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"New Date"},"new_time":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"New Time"}},"additionalProperties":true,"type":"object","title":"RescheduleRequest","description":"Body of the `reschedule_my_appointment` tool (2026-06-16). agent_id/caller_phone are\nEL-injected (the security boundary); date/time are LLM-OPTIONAL disambiguators for WHICH\nEXISTING booking to move; new_date/new_time are the REQUIRED target slot."},"ResetBody":{"properties":{"token":{"type":"string","title":"Token"},"new_password":{"type":"string","title":"New Password"}},"type":"object","required":["token","new_password"],"title":"ResetBody"},"SalesLoginRequest":{"properties":{"phone":{"type":"string","title":"Phone"},"password":{"type":"string","title":"Password"}},"type":"object","required":["phone","password"],"title":"SalesLoginRequest"},"SalesLoginResponse":{"properties":{"access_token":{"type":"string","title":"Access Token"},"user":{"$ref":"#/components/schemas/SalesRepPublic"}},"type":"object","required":["access_token","user"],"title":"SalesLoginResponse"},"SalesRepPublic":{"properties":{"id":{"type":"string","title":"Id"},"name":{"type":"string","title":"Name"},"phone":{"type":"string","title":"Phone"},"email":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Email"},"is_admin":{"type":"boolean","title":"Is Admin","default":false},"is_active":{"type":"boolean","title":"Is Active","default":true},"created_at":{"type":"string","title":"Created At"},"commission_rate_first_3m":{"type":"number","title":"Commission Rate First 3M","default":0.5},"commission_rate_after":{"type":"number","title":"Commission Rate After","default":0.1}},"type":"object","required":["id","name","phone","created_at"],"title":"SalesRepPublic"},"SetEmailRequest":{"properties":{"email":{"type":"string","title":"Email"}},"type":"object","required":["email"],"title":"SetEmailRequest"},"SetPasswordRequest":{"properties":{"new_password":{"type":"string","title":"New Password"}},"type":"object","required":["new_password"],"title":"SetPasswordRequest"},"SetTimezoneRequest":{"properties":{"timezone":{"type":"string","title":"Timezone"}},"type":"object","required":["timezone"],"title":"SetTimezoneRequest"},"SubscriptionInfo":{"properties":{"id":{"type":"string","title":"Id"},"plan":{"type":"string","title":"Plan"},"status":{"type":"string","title":"Status"},"minutes_limit":{"type":"integer","title":"Minutes Limit"},"provisioned_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Provisioned Number"},"trial_ends_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Trial Ends At"},"subscription_ends_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Subscription Ends At"},"stripe_customer_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Stripe Customer Id"}},"type":"object","required":["id","plan","status","minutes_limit"],"title":"SubscriptionInfo"},"SubscriptionListItem":{"properties":{"id":{"type":"string","title":"Id"},"user_id":{"type":"string","title":"User Id"},"plan":{"type":"string","title":"Plan"},"status":{"type":"string","title":"Status"},"minutes_limit":{"type":"integer","title":"Minutes Limit"},"stripe_subscription_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Stripe Subscription Id"},"stripe_customer_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Stripe Customer Id"},"provisioned_number":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Provisioned Number"},"created_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Created At"},"updated_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Updated At"}},"type":"object","required":["id","user_id","plan","status","minutes_limit"],"title":"SubscriptionListItem"},"SubscriptionListResponse":{"properties":{"subscriptions":{"items":{"$ref":"#/components/schemas/SubscriptionListItem"},"type":"array","title":"Subscriptions"},"total":{"type":"integer","title":"Total"},"limit":{"type":"integer","title":"Limit"},"offset":{"type":"integer","title":"Offset"}},"type":"object","required":["subscriptions","total","limit","offset"],"title":"SubscriptionListResponse"},"TenantDetailResponse":{"properties":{"id":{"type":"string","title":"Id"},"phone":{"type":"string","title":"Phone"},"email":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Email"},"status":{"type":"string","title":"Status"},"created_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Created At"},"last_login":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Last Login"},"subscription":{"anyOf":[{"$ref":"#/components/schemas/SubscriptionInfo"},{"type":"null"}]},"agents":{"items":{"$ref":"#/components/schemas/AgentInfo"},"type":"array","title":"Agents","default":[]},"usage":{"anyOf":[{"$ref":"#/components/schemas/UsageInfo"},{"type":"null"}]}},"type":"object","required":["id","phone","status"],"title":"TenantDetailResponse"},"TenantListItem":{"properties":{"id":{"type":"string","title":"Id"},"phone":{"type":"string","title":"Phone"},"email":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Email"},"status":{"type":"string","title":"Status"},"agents_count":{"type":"integer","title":"Agents Count","default":0},"has_subscription":{"type":"boolean","title":"Has Subscription","default":false},"plan":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Plan"},"subscription_status":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Subscription Status"},"created_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Created At"},"last_login":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Last Login"}},"type":"object","required":["id","phone","status"],"title":"TenantListItem"},"TenantListResponse":{"properties":{"users":{"items":{"$ref":"#/components/schemas/TenantListItem"},"type":"array","title":"Users"},"total":{"type":"integer","title":"Total"},"limit":{"type":"integer","title":"Limit"},"offset":{"type":"integer","title":"Offset"}},"type":"object","required":["users","total","limit","offset"],"title":"TenantListResponse"},"TestCallReleaseRequest":{"properties":{"release_token":{"type":"string","title":"Release Token","description":"Opaque slot id from /api/test-call/token (mint nonce).","default":""}},"type":"object","title":"TestCallReleaseRequest","description":"Best-effort release of THIS user's live test-session slot on call end.\n\n`release_token` is the opaque mint nonce returned by /api/test-call/token. The\nuser is taken from the JWT (NEVER from the body), so a token can only release a\nslot under the caller's own key. Idempotent + best-effort by design."},"TestCallReleaseResponse":{"properties":{"success":{"type":"boolean","title":"Success","default":true},"released":{"type":"boolean","title":"Released","default":false}},"type":"object","title":"TestCallReleaseResponse","description":"Always-OK ack for a release attempt (released True iff a live slot was freed)."},"TestCallStateResponse":{"properties":{"agent_id":{"type":"string","title":"Agent Id"},"phone_e164":{"type":"string","title":"Phone E164"},"call_count":{"type":"integer","title":"Call Count","description":"Ile rozmów ten numer odbył z TYM agentem"},"can_first_call":{"type":"boolean","title":"Can First Call","description":"True gdy trial aktywny ORAZ agent gotowy (po provisioningu)"},"can_second_call":{"type":"boolean","title":"Can Second Call","description":"True gdy call_count >= 1 (agent już coś zapamiętał) i agent gotowy"},"remembered_name":{"type":"string","title":"Remembered Name","description":"Zapamiętane imię usera (jeśli jest) — opener przy 2. rozmowie","default":""},"trial_active":{"type":"boolean","title":"Trial Active"},"trial_block_reason":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Trial Block Reason","description":"Powód blokady: kod trialu gdy trial nieaktywny, albo 'agent_provisioning' gdy trial OK ale agent jest jeszcze tworzony (0/7 -> 7/7)."},"remaining_minutes":{"type":"number","title":"Remaining Minutes","default":0.0}},"type":"object","required":["agent_id","phone_e164","call_count","can_first_call","can_second_call","trial_active"],"title":"TestCallStateResponse","description":"Stan 1st/2nd call dla agenta usera (gating przycisków we froncie)."},"TestCallTokenRequest":{"properties":{"agent_id":{"type":"string","title":"Agent Id","description":"ID agenta zalogowanego usera (musi należeć do niego)"}},"type":"object","required":["agent_id"],"title":"TestCallTokenRequest","description":"Request o WebRTC token do testu in-app."},"TestCallTokenResponse":{"properties":{"success":{"type":"boolean","title":"Success","default":true},"token":{"type":"string","title":"Token","description":"Krótkożyjący conversation/WebRTC token EL"},"agent_id":{"type":"string","title":"Agent Id"},"connection_type":{"type":"string","title":"Connection Type","default":"webrtc"},"phone_e164":{"type":"string","title":"Phone E164","description":"Zweryfikowany numer usera = klucz pamięci caller_memory"},"remaining_minutes":{"type":"number","title":"Remaining Minutes","description":"Pozostałe minuty trialu (po stronie usera)"},"max_session_seconds":{"type":"integer","title":"Max Session Seconds","description":"Per-call hard cap in seconds = min(agent max, remaining trial + buffer).","default":0},"trial_deadline_epoch":{"type":"integer","title":"Trial Deadline Epoch","description":"Absolute epoch (UTC seconds) at which the frontend MUST endSession().","default":0},"precutoff_lead_seconds":{"type":"integer","title":"Precutoff Lead Seconds","description":"Seconds before the cap to surface the 'about a minute left' warning.","default":0},"release_token":{"type":"string","title":"Release Token","description":"Opaque slot id; POST to /api/test-call/release on call end to free the slot.","default":""},"dynamic_variables":{"additionalProperties":true,"type":"object","title":"Dynamic Variables","description":"Zmienne pamięci EL do startSession (returning-caller opener wg ARIA). Te SAME zmienne, które inbound/Twilio pushuje przez register-call. Front przekazuje je do Conversation.startSession({dynamicVariables}). ZAWSZE kompletny zestaw — w tym returning_first_message: dla first-time callera = pierwszorazowy greeting agenta (EL NIE back-filluje defaultem placeholdera, gdy klient przekazuje dynamic variables — live error 1008 'Missing required dynamic variables', 2026-06-12), dla returning callera = spersonalizowany opener."}},"type":"object","required":["token","agent_id","phone_e164","remaining_minutes"],"title":"TestCallTokenResponse","description":"WebRTC token + metadane do startu sesji EL po stronie frontu."},"UpdateWorkerRequest":{"properties":{"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name"},"email":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Email"},"is_active":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Is Active"},"commission_rate_first_3m":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Commission Rate First 3M"},"commission_rate_after":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Commission Rate After"}},"type":"object","title":"UpdateWorkerRequest"},"UsageAddRequest":{"properties":{"user_id":{"type":"string","title":"User Id"},"duration_sec":{"type":"integer","title":"Duration Sec"},"usage_key":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Usage Key"}},"type":"object","required":["user_id","duration_sec"],"title":"UsageAddRequest"},"UsageCheckRequest":{"properties":{"agent_id":{"type":"string","title":"Agent Id"}},"type":"object","required":["agent_id"],"title":"UsageCheckRequest"},"UsageInfo":{"properties":{"minutes_used":{"type":"number","title":"Minutes Used","default":0},"minutes_limit":{"type":"integer","title":"Minutes Limit","default":0},"minutes_remaining":{"type":"number","title":"Minutes Remaining","default":0},"usage_percentage":{"type":"number","title":"Usage Percentage","default":0},"calls_count":{"type":"integer","title":"Calls Count","default":0}},"type":"object","title":"UsageInfo"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"},"input":{"title":"Input"},"ctx":{"type":"object","title":"Context"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"},"VendorStatus":{"properties":{"name":{"type":"string","title":"Name"},"configured":{"type":"boolean","title":"Configured"},"status":{"type":"string","title":"Status"},"detail":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Detail"}},"type":"object","required":["name","configured","status"],"title":"VendorStatus"},"VoiceResponse":{"properties":{"voice_id":{"type":"string","title":"Voice Id"},"name":{"type":"string","title":"Name"},"description":{"type":"string","title":"Description"},"icon":{"type":"string","title":"Icon"},"gender":{"type":"string","title":"Gender","default":""},"default_persona_name":{"type":"string","title":"Default Persona Name","default":""}},"type":"object","required":["voice_id","name","description","icon"],"title":"VoiceResponse","description":"Available voice. `gender` + `default_persona_name` let the client auto-sync\nthe receptionist name when the owner switches voice (so a male voice never\nkeeps a female persona name)."},"WorkerDetail":{"properties":{"rep":{"$ref":"#/components/schemas/SalesRepPublic"},"metrics":{"$ref":"#/components/schemas/RepDashboard"},"leads":{"items":{"$ref":"#/components/schemas/LeadResponse"},"type":"array","title":"Leads"},"commissions":{"items":{"$ref":"#/components/schemas/CommissionResponse"},"type":"array","title":"Commissions"},"payouts":{"items":{"$ref":"#/components/schemas/PayoutResponse"},"type":"array","title":"Payouts"}},"type":"object","required":["rep","metrics","leads","commissions","payouts"],"title":"WorkerDetail"},"WorkerSummary":{"properties":{"id":{"type":"string","title":"Id"},"name":{"type":"string","title":"Name"},"phone":{"type":"string","title":"Phone"},"is_active":{"type":"boolean","title":"Is Active"},"total_leads":{"type":"integer","title":"Total Leads"},"demo_rate":{"type":"number","title":"Demo Rate"},"trial_rate":{"type":"number","title":"Trial Rate"},"paid_rate":{"type":"number","title":"Paid Rate"},"active_clients":{"type":"integer","title":"Active Clients"},"earned_total":{"type":"number","title":"Earned Total"},"pending_payout":{"type":"number","title":"Pending Payout"},"last_activity":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Last Activity"}},"type":"object","required":["id","name","phone","is_active","total_leads","demo_rate","trial_rate","paid_rate","active_clients","earned_total","pending_payout"],"title":"WorkerSummary"},"WorkingHours":{"properties":{"weekdays":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Weekdays"},"saturday":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Saturday"},"sunday":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Sunday"}},"type":"object","title":"WorkingHours","description":"Godziny pracy firmy"}},"securitySchemes":{"HTTPBearer":{"type":"http","scheme":"bearer"}}}}