# Public contract: api/dist/openapi.yaml without what is marked x-internal.
# Written by `make spec-bundle` (tools/docsite). Do not edit.
openapi: 3.1.0
info:
  title: Elunyo API
  version: 0.9.0
  summary: API for Elunyo, a pay-per-use AI chat priced in kwanzas.
  description: |
    Contract for the Elunyo API. This document is the source of truth: the
    backend generates its types and server interfaces from it, and the
    frontend generates its types, functions and hooks.

    ## Conventions

    - **Version in the path.** Every path starts with `/v1`. Within v1 only
      additive changes are allowed: new optional fields, new endpoints and new
      values in enums documented as extensible.
    - **Names.** Fields are `snake_case`. Dates are RFC 3339, always in UTC.
    - **Errors.** Every error response uses `application/problem+json`
      (RFC 9457) with the `Problem` schema. The `code` field is stable and is
      the key clients translate for end users. `title` and `detail` are
      English text for developers and logs, and are never shown to end users.
    - **Request id.** Every response carries the `X-Request-ID` header. The
      client may send its own in the request: 1 to 64 letters, digits, `.`,
      `_` or `-`. Otherwise, or if the value is not in that format, the server
      generates a UUIDv7. The same value appears as `request_id` in errors.
    - **Stability.** Every operation declares `x-stability`. A `beta`
      operation may change without notice. A `stable` operation follows the
      additive-changes rule.
    - **Sessions and CSRF.** The web app signs in with a social provider and
      gets the `sid` cookie. Every request that changes state with that
      cookie must carry `X-Requested-With: elunyo-web`; without it the answer
      is 403. CORS only allows the web app's origin.
    - **Money.** Always `{"amount_cents": 1130, "currency": "AOA"}`, in
      integer cents. Prices are computed from data that changes without a
      deploy, never written in code.
    - **Pagination.** By cursor: `?cursor=...&limit=...`, answering
      `{"data": [...], "next_cursor": "..."}`. Never by offset.
    - **Internal endpoints.** Operations marked `x-internal: true` are left
      out of the public documentation.
servers:
  - url: https://api.elunyo.app
    description: Production.
  - url: http://localhost:8080
    description: Local development.
security:
  - cookieAuth: []
  - bearerAuth: []
tags:
  - name: system
    description: Service status and API metadata.
  - name: auth
    description: Social login and sessions.
  - name: me
    description: Profile, preferences, linked accounts and free quota of the signed-in user.
  - name: privacy
    description: The user's personal data, exported or deleted with the account.
  - name: catalog
    description: Models and prices.
  - name: conversations
    description: Conversations of the user.
  - name: messages
    description: Messages and answer streams.
  - name: wallet
    description: Balance and statement of the signed-in user.
  - name: payments
    description: Recharges of the balance.
  - name: images
    description: Images created from a prompt, and the gallery.
paths:
  /v1/health:
    get:
      operationId: getHealth
      summary: Service health
      description: |
        Reports whether this API instance is accepting requests. The load balancer
        polls this endpoint.

        The response does not depend on the database or the cache: it only says
        the process is up and not shutting down. During shutdown the instance
        answers 503, so the load balancer stops sending it requests.
      tags:
        - system
      security: []
      x-stability: stable
      responses:
        '200':
          description: The instance is accepting requests.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Health'
              examples:
                ok:
                  summary: Instance available
                  value:
                    status: ok
        '500':
          $ref: '#/components/responses/InternalError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
  /v1/meta:
    get:
      operationId: getMeta
      summary: API metadata
      description: |
        Returns the contract version this instance serves and the minimum web
        client version it accepts.

        The web app calls this endpoint on startup, before login. If its own
        version is below `min_web_version`, it shows the "update to continue"
        screen and makes no further requests.
      tags:
        - system
      security: []
      x-stability: beta
      responses:
        '200':
          description: API metadata.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Meta'
              examples:
                noMinimum:
                  summary: No minimum version set
                  value:
                    api_version: 0.1.0
                    min_web_version: 0.0.0
                withMinimum:
                  summary: Minimum web client version set
                  value:
                    api_version: 0.1.0
                    min_web_version: 2026.11.15
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/auth/{provider}/start:
    get:
      operationId: startAuth
      summary: Start a social login
      description: |
        Redirects the browser to the provider's consent page, with PKCE and a
        `state` kept for 10 minutes. The browser must open this URL itself
        (navigation, not `fetch`), because it ends on the provider's site.

        At the end, `GET /v1/auth/{provider}/callback` sends the browser back to
        the web app at `return_to`.

        In local development, without Google credentials, a fake consent page
        served by the API takes its place, so the whole flow runs offline.
      tags:
        - auth
      security: []
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/Provider'
        - name: return_to
          in: query
          required: false
          description: Path of the web app to open after signing in, starting with `/`. Default `/chat`.
          schema:
            type: string
            maxLength: 200
        - name: intent
          in: query
          required: false
          description: Sign in (default) or link another account to the signed-in user.
          schema:
            $ref: '#/components/schemas/AuthIntent'
        - name: locale
          in: query
          required: false
          description: |
            Interface language the web app was showing. A new account starts in
            it; without it, the API picks one from `Accept-Language`. Ignored
            for existing accounts.
          schema:
            $ref: '#/components/schemas/Locale'
      responses:
        '302':
          description: Go to the provider. A short-lived cookie ties the flow to this browser.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
            Location:
              $ref: '#/components/headers/Location'
            Set-Cookie:
              $ref: '#/components/headers/SetCookie'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/auth/{provider}/callback:
    get:
      operationId: completeAuth
      summary: Finish a social login
      description: |
        The provider sends the browser here. The API checks `state`, exchanges
        the code and signs the user in, creating the account on the first time.
        A sign-in with an email the provider verified joins an account that has
        that email and no account of that provider yet.

        It always answers with a redirect to the web app:

        - on success, to the `return_to` given at the start, with the `sid`
          session cookie set;
        - on failure, to `/login?error=<code>`, where the code is one of
          `access_denied` (the user said no), `invalid_state` (expired or
          tampered flow, or a provider that is not offered), `identity_in_use`
          (when linking, the account belongs to another user, or the user
          already has one of that provider), `rate_limited` (too many sign-ins from this
          address), `unavailable` (our service failed) or `provider_error`.

        A link (`intent=link`) goes back to its `return_to` with `?linked=<provider>`
        on success or `?error=<code>` on failure.
      tags:
        - auth
      security: []
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/Provider'
        - name: code
          in: query
          required: false
          description: Authorization code from the provider.
          schema:
            type: string
            maxLength: 2048
        - name: state
          in: query
          required: false
          description: The `state` sent at the start.
          schema:
            type: string
            maxLength: 200
        - name: error
          in: query
          required: false
          description: Error from the provider, such as `access_denied`.
          schema:
            type: string
            maxLength: 200
      responses:
        '302':
          description: Back to the web app, signed in or with an error code.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
            Location:
              $ref: '#/components/headers/Location'
            Set-Cookie:
              $ref: '#/components/headers/SetCookie'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/auth/logout:
    post:
      operationId: logout
      summary: Sign out
      description: Ends the current session on every instance and clears the `sid` cookie.
      tags:
        - auth
      x-stability: beta
      responses:
        '204':
          description: Signed out.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
            Set-Cookie:
              $ref: '#/components/headers/SetCookie'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/me:
    get:
      operationId: getMe
      summary: Current user
      description: |
        Profile and preferences of the signed-in user. The web app calls it on
        startup: a 401 means it shows the sign-in screen.
      tags:
        - me
      x-stability: beta
      responses:
        '200':
          description: The signed-in user.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
              examples:
                user:
                  summary: A user
                  value:
                    id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
                    name: Ana Domingos
                    email: ana.domingos@example.com
                    avatar_url: null
                    locale: pt-AO
                    created_at: '2026-10-02T09:15:00Z'
                    is_new: false
                    preferences:
                      theme: system
                      default_model_id: null
                      image_quality: standard
                      confirm_expensive: true
                      confirm_above:
                        amount_cents: 5000
                        currency: AOA
                      low_balance_alert: true
                      low_balance_threshold:
                        amount_cents: 20000
                        currency: AOA
                      retention_days: 90
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '500':
          $ref: '#/components/responses/InternalError'
    patch:
      operationId: updateMe
      summary: Change the profile or preferences
      description: Changes the name, the interface language or preferences. Fields left out keep their value.
      tags:
        - me
      x-stability: beta
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateMeRequest'
            examples:
              theme:
                summary: Change the theme
                value:
                  preferences:
                    theme: dark
              name:
                summary: Rename
                value:
                  name: Ana Domingos
      responses:
        '200':
          description: The user after the change.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
              examples:
                user:
                  summary: Updated user
                  value:
                    id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
                    name: Ana Domingos
                    email: ana.domingos@example.com
                    avatar_url: null
                    locale: pt-AO
                    created_at: '2026-10-02T09:15:00Z'
                    is_new: false
                    preferences:
                      theme: system
                      default_model_id: null
                      image_quality: standard
                      confirm_expensive: true
                      confirm_above:
                        amount_cents: 5000
                        currency: AOA
                      low_balance_alert: true
                      low_balance_threshold:
                        amount_cents: 20000
                        currency: AOA
                      retention_days: 90
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '500':
          $ref: '#/components/responses/InternalError'
    delete:
      operationId: deleteMe
      summary: Delete the account
      description: |
        Deletes the account at once. The conversations, images, statement,
        preferences, exports and personal data go; pending payments
        are canceled; the balance is lost to a ledger account kept as the tax
        record. Every session ends and the `sid` cookie is cleared.

        The user and the linked accounts (provider and its id) stay, empty: a new
        sign-in with one of them opens the same account, with nothing in it.

        While an answer or an image is being paid for, the account cannot be
        deleted (`generation_in_progress`): try again when it ends.
      tags:
        - privacy
      x-stability: beta
      responses:
        '204':
          description: Deleted and signed out.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
            Set-Cookie:
              $ref: '#/components/headers/SetCookie'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/me/quota:
    get:
      operationId: getQuota
      summary: Free messages of today
      description: |
        How many free messages are left today and when they reset (midnight in
        Luanda). The `done` event of each answer also carries `quota_remaining`,
        so clients need not call this after every message.
      tags:
        - me
      x-stability: beta
      responses:
        '200':
          description: Today's quota.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Quota'
              examples:
                quota:
                  summary: 3 used
                  value:
                    limit: 20
                    used: 3
                    remaining: 17
                    resets_at: '2026-11-20T23:00:00Z'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/me/export:
    get:
      operationId: getExport
      summary: The latest export of the user's data
      description: |
        The latest request for a file with the user's data. While it is
        `preparing`, ask again every few seconds. Once `ready`, `url`
        downloads a ZIP with the data in JSON and the images, until
        `expires_at` (24 hours after it was ready). A 404 means the user never
        asked for one.
      tags:
        - privacy
      x-stability: beta
      responses:
        '200':
          description: The latest export.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataExport'
              examples:
                preparing:
                  summary: Being prepared
                  value:
                    id: 0193d1a0-2b3c-7d4e-8f50-6a7b8c9d0e1f
                    status: preparing
                    created_at: '2026-11-21T14:00:00Z'
                    ready_at: null
                    expires_at: null
                    size_bytes: null
                    url: null
                    next_request_at: '2026-11-22T14:00:00Z'
                ready:
                  summary: Ready to download
                  value:
                    id: 0193d1a0-2b3c-7d4e-8f50-6a7b8c9d0e1f
                    status: ready
                    created_at: '2026-11-21T14:00:00Z'
                    ready_at: '2026-11-21T14:00:40Z'
                    expires_at: '2026-11-22T14:00:40Z'
                    size_bytes: 3481920
                    url: https://img.elunyo.example/exports/0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10/0193d1a0-2b3c-7d4e-8f50-6a7b8c9d0e1f.zip?Policy=x&Signature=y&Key-Pair-Id=z
                    next_request_at: '2026-11-22T14:00:00Z'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
    post:
      operationId: requestExport
      summary: Ask for a file with the user's data
      description: |
        Starts a ZIP with the profile, preferences, conversations, images,
        statement and payments. The worker builds it; follow it with
        `GET /v1/me/export`. One request per 24 hours: earlier, the answer is
        429 with `Retry-After`, unless the last one failed.
      tags:
        - privacy
      x-stability: beta
      responses:
        '202':
          description: Being prepared.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataExport'
              examples:
                preparing:
                  summary: Being prepared
                  value:
                    id: 0193d1a0-2b3c-7d4e-8f50-6a7b8c9d0e1f
                    status: preparing
                    created_at: '2026-11-21T14:00:00Z'
                    ready_at: null
                    expires_at: null
                    size_bytes: null
                    url: null
                    next_request_at: '2026-11-22T14:00:00Z'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
  /v1/me/identities:
    get:
      operationId: listIdentities
      summary: Linked social accounts
      description: Social accounts the user can sign in with. Today that is the Google account; linking another (`GET /v1/auth/{provider}/start?intent=link`) waits for a second way to sign in.
      tags:
        - me
      x-stability: beta
      responses:
        '200':
          description: Linked accounts.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IdentityList'
              examples:
                google:
                  summary: Google only
                  value:
                    data:
                      - provider: google
                        email: ana.domingos@example.com
                        created_at: '2026-10-02T09:15:00Z'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/me/identities/{provider}:
    delete:
      operationId: unlinkIdentity
      summary: Unlink a social account
      description: Removes a linked account. The last one cannot be removed (`last_identity`), and with Google as the only provider that is always the Google account.
      tags:
        - me
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/Provider'
      responses:
        '204':
          description: Unlinked.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/models:
    get:
      operationId: listModels
      summary: Model catalog
      description: |
        Text models with their prices in kwanzas, computed from the list prices,
        the exchange rate and the plan parameters in the database. Public: the
        landing page uses it too. Cached for 60 seconds; the `ETag` is the
        `pricing_version`.
      tags:
        - catalog
      security: []
      x-stability: beta
      responses:
        '200':
          description: The catalog.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
            Cache-Control:
              $ref: '#/components/headers/CacheControl'
            ETag:
              $ref: '#/components/headers/ETag'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ModelList'
              examples:
                catalog:
                  summary: One free and one strong model
                  value:
                    pricing_version: pv_9f2c1a7e
                    data:
                      - id: gemini-2.5-flash-lite
                        display_name: Gemini 2.5 Flash-Lite
                        maker: Google
                        group: free
                        description:
                          pt_ao: Respostas rápidas e simples
                          en: Quick and simple answers
                        data_location: null
                        free_eligible: true
                        available: true
                        short_message_price:
                          amount_cents: 60
                          currency: AOA
                        price_per_mtok_in:
                          amount_cents: 27267
                          currency: AOA
                        price_per_mtok_out:
                          amount_cents: 109067
                          currency: AOA
                        context_window: 1000000
                        max_output_tokens: 8192
                      - id: sonnet-5.5
                        display_name: Sonnet 5.5
                        maker: Anthropic
                        group: strong
                        description:
                          pt_ao: Textos, trabalho e código
                          en: Writing, work and code
                        data_location: null
                        free_eligible: false
                        available: true
                        short_message_price:
                          amount_cents: 1364
                          currency: AOA
                        price_per_mtok_in:
                          amount_cents: 545331
                          currency: AOA
                        price_per_mtok_out:
                          amount_cents: 2726652
                          currency: AOA
                        context_window: 200000
                        max_output_tokens: 8192
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/pricing:
    get:
      operationId: getPricing
      summary: Pricing summary
      description: |
        Public summary for the sign-in screen, the paywall, the composer and the
        landing page: recharge amounts and what they buy, the daily free
        messages and the image qualities with their prices. Cached for 60
        seconds.
      tags:
        - catalog
      security: []
      x-stability: beta
      responses:
        '200':
          description: The pricing summary.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
            Cache-Control:
              $ref: '#/components/headers/CacheControl'
            ETag:
              $ref: '#/components/headers/ETag'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pricing'
              examples:
                pricing:
                  summary: Two recharge amounts
                  value:
                    pricing_version: pv_9f2c1a7e
                    updated_at: '2026-11-01T00:00:00Z'
                    free_daily_messages: 20
                    recharge_options:
                      - amount:
                          amount_cents: 50000
                          currency: AOA
                        iva:
                          amount_cents: 6140
                          currency: AOA
                        featured: false
                        yields:
                          - model_id: sonnet-5.5
                            display_name: Sonnet 5.5
                            messages: 36
                        image_yields:
                          - quality: standard
                            images: 3
                          - quality: premium
                            images: 0
                      - amount:
                          amount_cents: 100000
                          currency: AOA
                        iva:
                          amount_cents: 12281
                          currency: AOA
                        featured: true
                        yields:
                          - model_id: sonnet-5.5
                            display_name: Sonnet 5.5
                            messages: 73
                        image_yields:
                          - quality: standard
                            images: 6
                          - quality: premium
                            images: 1
                    recharge_min:
                      amount_cents: 50000
                      currency: AOA
                    recharge_max:
                      amount_cents: 5000000
                      currency: AOA
                    payment_methods:
                      - multicaixa_express
                      - reference
                    image_qualities:
                      - quality: standard
                        model_name: GPT Image 2
                        price:
                          amount_cents: 14452
                          currency: AOA
                        width: 1024
                        height: 1024
                        available: true
                      - quality: premium
                        model_name: GPT Image 2
                        price:
                          amount_cents: 57533
                          currency: AOA
                        width: 1024
                        height: 1024
                        available: true
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/conversations:
    get:
      operationId: listConversations
      summary: List conversations
      description: Conversations of the user, last updated first, by cursor. `q` keeps those whose title contains the text.
      tags:
        - conversations
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/Cursor'
        - $ref: '#/components/parameters/Limit'
        - name: q
          in: query
          required: false
          description: Text to look for in the titles, ignoring case.
          schema:
            type: string
            maxLength: 100
      responses:
        '200':
          description: A page of conversations.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConversationPage'
              examples:
                page:
                  summary: Last page
                  value:
                    next_cursor: null
                    data:
                      - id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
                        title: Cartaz da promoção de sábado
                        created_at: '2026-11-20T08:12:00Z'
                        updated_at: '2026-11-20T08:20:31Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '500':
          $ref: '#/components/responses/InternalError'
    post:
      operationId: createConversation
      summary: Create a conversation
      description: Creates an empty conversation. Messages are sent with `POST /v1/conversations/{conversation_id}/messages`.
      tags:
        - conversations
      x-stability: beta
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateConversationRequest'
            examples:
              empty:
                summary: Title from the first message
                value: {}
      responses:
        '201':
          description: The new conversation.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Conversation'
              examples:
                conversation:
                  summary: New conversation
                  value:
                    id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
                    title: Cartaz da promoção de sábado
                    created_at: '2026-11-20T08:12:00Z'
                    updated_at: '2026-11-20T08:20:31Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
    delete:
      operationId: deleteAllConversations
      summary: Delete every conversation
      description: Deletes the history of the user. The balance is not touched. Answers in progress are stopped.
      tags:
        - conversations
      x-stability: beta
      responses:
        '204':
          description: Deleted.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/conversations/{conversation_id}:
    parameters:
      - $ref: '#/components/parameters/ConversationId'
    get:
      operationId: getConversation
      summary: Get a conversation
      description: One conversation of the user.
      tags:
        - conversations
      x-stability: beta
      responses:
        '200':
          description: The conversation.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Conversation'
              examples:
                conversation:
                  summary: A conversation
                  value:
                    id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
                    title: Cartaz da promoção de sábado
                    created_at: '2026-11-20T08:12:00Z'
                    updated_at: '2026-11-20T08:20:31Z'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
    patch:
      operationId: updateConversation
      summary: Rename a conversation
      description: Changes the title.
      tags:
        - conversations
      x-stability: beta
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateConversationRequest'
            examples:
              rename:
                summary: New title
                value:
                  title: Legendas para o Instagram
      responses:
        '200':
          description: The renamed conversation.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Conversation'
              examples:
                conversation:
                  summary: Renamed
                  value:
                    id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
                    title: Cartaz da promoção de sábado
                    created_at: '2026-11-20T08:12:00Z'
                    updated_at: '2026-11-20T08:20:31Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
    delete:
      operationId: deleteConversation
      summary: Delete a conversation
      description: Deletes the conversation and its messages. An answer in progress is stopped.
      tags:
        - conversations
      x-stability: beta
      responses:
        '204':
          description: Deleted.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/conversations/{conversation_id}/messages:
    parameters:
      - $ref: '#/components/parameters/ConversationId'
    get:
      operationId: listMessages
      summary: List messages
      description: Messages of a conversation, newest first, by cursor. Clients show them oldest first.
      tags:
        - messages
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/Cursor'
        - $ref: '#/components/parameters/Limit'
      responses:
        '200':
          description: A page of messages.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessagePage'
              examples:
                page:
                  summary: A question and its answer
                  value:
                    next_cursor: null
                    data:
                      - id: 0193c4f9-1d2e-7a3b-8c4d-5e6f7a8b9c0d
                        conversation_id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
                        role: assistant
                        kind: text
                        content: Experimenta este resumo.
                        model_id: gemini-2.5-flash-lite
                        status: done
                        funding: free
                        cost:
                          amount_cents: 0
                          currency: AOA
                        error_code: null
                        truncated: false
                        image: null
                        created_at: '2026-11-20T08:20:31Z'
                        completed_at: '2026-11-20T08:20:36Z'
                      - id: 0193c4f9-1d2d-7f00-9a1b-2c3d4e5f6a7b
                        conversation_id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
                        role: user
                        kind: text
                        content: Ajuda-me a escrever o resumo do meu CV.
                        model_id: null
                        status: done
                        funding: null
                        cost: null
                        error_code: null
                        truncated: false
                        image: null
                        created_at: '2026-11-20T08:20:31Z'
                        completed_at: '2026-11-20T08:20:31Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
    post:
      operationId: sendMessage
      summary: Send a message
      description: |
        Saves the user message and streams the model's answer as Server-Sent
        Events (`ChatStreamEvent`).

        Before the stream starts, the API decides what pays: a free message of
        today for models of the free group while the quota lasts, otherwise the
        balance. Without either, it answers 402 and nothing is saved.

        The answer is generated apart from this connection. If the connection
        drops, `GET /v1/messages/{message_id}/stream` continues from the last
        event. If nobody reads the stream for 30 seconds, the answer is stopped
        and only the delivered tokens count.

        Sending the same `client_message_id` again streams the answer already
        started instead of creating another one.
      tags:
        - messages
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SendMessageRequest'
            examples:
              free:
                summary: Message to a free model
                value:
                  model_id: gemini-2.5-flash-lite
                  content: Ajuda-me a escrever o resumo do meu CV.
                  client_message_id: 6f1c2b3a-4d5e-4f60-8a7b-9c0d1e2f3a4b
      responses:
        '200':
          description: The answer, as a stream of events.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            text/event-stream:
              schema:
                $ref: '#/components/schemas/ChatStreamEvent'
              examples:
                delta:
                  summary: Data of a delta event
                  value:
                    type: delta
                    text: O contrato dura 12 meses
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
        '503':
          $ref: '#/components/responses/ChatUnavailable'
  /v1/messages/{message_id}/stream:
    get:
      operationId: streamMessage
      summary: Resume an answer
      description: |
        Streams an answer from the event after `Last-Event-ID`, on any instance.
        For an answer that already finished, it sends the events that remain.
        When they are no longer kept (10 minutes after the end), the answer is
        sent again from the start: `meta`, the whole text in one `delta`, then
        `done` or `error`, with ids after `Last-Event-ID`. A client that
        receives `meta` again starts the text over.

        Only `text` answers have a stream: an `image` answer answers 404; read
        its image with `GET /v1/images/{image_id}`.
      tags:
        - messages
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/MessageId'
        - $ref: '#/components/parameters/LastEventId'
      responses:
        '200':
          description: The rest of the answer, as a stream of events.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            text/event-stream:
              schema:
                $ref: '#/components/schemas/ChatStreamEvent'
              examples:
                done:
                  summary: Data of a done event
                  value:
                    type: done
                    message_id: 0193c4f9-1d2e-7a3b-8c4d-5e6f7a8b9c0d
                    status: done
                    cost:
                      amount_cents: 0
                      currency: AOA
                    input_tokens: 812
                    output_tokens: 264
                    quota_remaining: 16
                    balance: null
                    truncated: false
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/messages/{message_id}/cancel:
    post:
      operationId: cancelMessage
      summary: Stop an answer
      description: |
        Stops an answer in progress. The provider request is canceled and only
        the tokens already delivered count. The stream ends with `done` and
        status `canceled`. Stopping an answer that already finished does
        nothing.
      tags:
        - messages
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/MessageId'
      responses:
        '202':
          description: The stop was requested.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/messages/estimate:
    post:
      operationId: estimateMessage
      summary: Estimate a message
      description: |
        What a message would cost before it is sent, with the real history of
        the conversation, and whether the user asked to confirm it. Free
        messages of today cost nothing.
      tags:
        - messages
      x-stability: beta
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EstimateRequest'
            examples:
              paid:
                summary: Message to a paid model
                value:
                  model_id: sonnet-5.5
                  content: Resume este contrato em cinco pontos.
                  conversation_id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
      responses:
        '200':
          description: The estimate.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Estimate'
              examples:
                confirm:
                  summary: Above the user's threshold
                  value:
                    model_id: sonnet-5.5
                    funding: wallet
                    cost:
                      amount_cents: 6200
                      currency: AOA
                    confirm: true
                    balance:
                      amount_cents: 234000
                      currency: AOA
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/pricing/recharge:
    get:
      operationId: getRechargeQuote
      summary: Quote a recharge amount
      description: |
        The IVA included in an amount and what it buys: short messages in the
        featured models and images in each quality, for the "Other amount"
        field. The amount must be between `recharge_min`
        and `recharge_max` of `GET /v1/pricing`.
      tags:
        - catalog
      security: []
      x-stability: beta
      parameters:
        - name: amount_cents
          in: query
          required: true
          description: Amount in cents, IVA included.
          schema:
            type: integer
            format: int64
            minimum: 1
            examples:
              - 150000
      responses:
        '200':
          description: The quote.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RechargeQuote'
              examples:
                quote:
                  summary: 1.500 Kz
                  value:
                    amount:
                      amount_cents: 150000
                      currency: AOA
                    iva:
                      amount_cents: 18421
                      currency: AOA
                    yields:
                      - model_id: sonnet-5.5
                        display_name: Sonnet 5.5
                        messages: 109
                    image_yields:
                      - quality: standard
                        images: 10
                      - quality: premium
                        images: 2
        '400':
          $ref: '#/components/responses/BadRequest'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/wallet:
    get:
      operationId: getWallet
      summary: Balance
      description: |
        Balance available, amount held by answers in progress, what the month
        cost so far, and whether to show the low-balance notice. The `done`
        event of a paid answer carries the new balance too.
      tags:
        - wallet
      x-stability: beta
      responses:
        '200':
          description: The balance.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Wallet'
              examples:
                wallet:
                  summary: Balance after a recharge
                  value:
                    balance:
                      amount_cents: 234000
                      currency: AOA
                    held:
                      amount_cents: 0
                      currency: AOA
                    low_balance: false
                    last_phone: '923456567'
                    month_spending:
                      month: 2026-11
                      total:
                        amount_cents: 166000
                        currency: AOA
                      conversations:
                        amount_cents: 113000
                        currency: AOA
                      images:
                        amount_cents: 53000
                        currency: AOA
                    yields:
                      - model_id: sonnet-5.5
                        display_name: Sonnet 5.5
                        messages: 171
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/wallet/transactions:
    get:
      operationId: listTransactions
      summary: Statement
      description: |
        Recharges and charges, newest first, by cursor. Answers are added up per
        conversation and per day in Luanda, so a long chat is one line.
      tags:
        - wallet
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/Cursor'
        - $ref: '#/components/parameters/Limit'
      responses:
        '200':
          description: A page of statement lines.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionPage'
              examples:
                page:
                  summary: A charge and a recharge
                  value:
                    next_cursor: null
                    data:
                      - id: 0193c5a1-0c1d-7e2f-8a3b-4c5d6e7f8a9b
                        kind: conversation
                        amount:
                          amount_cents: -4600
                          currency: AOA
                        title: Resumo do contrato
                        conversation_id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
                        payment_method: null
                        count: 3
                        occurred_at: '2026-11-12T10:15:00Z'
                      - id: 0193c5a0-4b1c-7d2e-9f30-1a2b3c4d5e6f
                        kind: top_up
                        amount:
                          amount_cents: 100000
                          currency: AOA
                        title: null
                        conversation_id: null
                        payment_method: multicaixa_express
                        count: 1
                        occurred_at: '2026-11-12T09:40:00Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/payments:
    post:
      operationId: createPayment
      summary: Start a recharge
      description: |
        Creates a pending payment at the gateway and returns what the user does
        to pay. The balance is credited when the gateway confirms it; clients
        poll `GET /v1/payments/{payment_id}` every 3 seconds meanwhile.
      tags:
        - payments
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/IdempotencyKeyRequired'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreatePaymentRequest'
            examples:
              multicaixaExpress:
                summary: 1.000 Kz with Multicaixa Express
                value:
                  amount_cents: 100000
                  method: multicaixa_express
                  phone: 923 456 567
              reference:
                summary: 2.000 Kz by reference
                value:
                  amount_cents: 200000
                  method: reference
      responses:
        '201':
          description: The payment, waiting to be paid.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Payment'
              examples:
                pending:
                  summary: Waiting for the Multicaixa Express app
                  value:
                    id: 0193c5a0-4b1c-7d2e-9f30-1a2b3c4d5e6f
                    status: pending
                    method: multicaixa_express
                    amount:
                      amount_cents: 100000
                      currency: AOA
                    iva:
                      amount_cents: 12281
                      currency: AOA
                    balance_after:
                      amount_cents: 334000
                      currency: AOA
                    instructions:
                      phone: 923 ••• 567
                      entity: null
                      reference: null
                    expires_at: '2026-11-21T10:05:00Z'
                    paid_at: null
                    created_at: '2026-11-21T10:00:00Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          $ref: '#/components/responses/Conflict'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
  /v1/payments/{payment_id}:
    parameters:
      - $ref: '#/components/parameters/PaymentId'
    get:
      operationId: getPayment
      summary: Get a payment
      description: |
        A payment of the user. A pending payment past `expires_at` is reported
        as `expired`.
      tags:
        - payments
      x-stability: beta
      responses:
        '200':
          description: The payment.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Payment'
              examples:
                pending:
                  summary: Waiting for the Multicaixa Express app
                  value:
                    id: 0193c5a0-4b1c-7d2e-9f30-1a2b3c4d5e6f
                    status: pending
                    method: multicaixa_express
                    amount:
                      amount_cents: 100000
                      currency: AOA
                    iva:
                      amount_cents: 12281
                      currency: AOA
                    balance_after:
                      amount_cents: 334000
                      currency: AOA
                    instructions:
                      phone: 923 ••• 567
                      entity: null
                      reference: null
                    expires_at: '2026-11-21T10:05:00Z'
                    paid_at: null
                    created_at: '2026-11-21T10:00:00Z'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/payments/{payment_id}/cancel:
    parameters:
      - $ref: '#/components/parameters/PaymentId'
    post:
      operationId: cancelPayment
      summary: Cancel a payment
      description: |
        Cancels a pending payment at the gateway. Canceling one that is no
        longer pending changes nothing and returns it as it is; a payment that
        the gateway confirms later is still credited.
      tags:
        - payments
      x-stability: beta
      responses:
        '200':
          description: The payment after the request.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Payment'
              examples:
                canceled:
                  summary: Canceled before paying
                  value:
                    id: 0193c5a0-4b1c-7d2e-9f30-1a2b3c4d5e6f
                    status: canceled
                    method: multicaixa_express
                    amount:
                      amount_cents: 100000
                      currency: AOA
                    iva:
                      amount_cents: 12281
                      currency: AOA
                    balance_after:
                      amount_cents: 334000
                      currency: AOA
                    instructions:
                      phone: 923 ••• 567
                      entity: null
                      reference: null
                    expires_at: '2026-11-21T10:05:00Z'
                    paid_at: null
                    created_at: '2026-11-21T10:00:00Z'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/images:
    post:
      operationId: createImage
      summary: Create an image
      description: |
        Starts an image from a prompt and answers at once with the image
        `pending`; poll `GET /v1/images/{image_id}` every 1.5 seconds until it is
        `ready` or `failed`.

        The image is a turn of a conversation: a user message of kind `image`
        with the prompt, and an answer of kind `image` that shows it. Without
        `conversation_id` a new conversation is created, titled after the prompt.

        Images are always paid from the balance, never with free messages. The
        price of the quality (`GET /v1/pricing`) is held at once and charged only
        when the image is stored; a refused or failed image is not charged. An
        image that is not ready within about two minutes fails.
      tags:
        - images
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/IdempotencyKeyRequired'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateImageRequest'
            examples:
              newConversation:
                summary: A poster in a new conversation
                value:
                  prompt: 'Cartaz para a promoção de sábado: vestidos a 8.000 Kz, loja no Kilamba.'
                  quality: standard
      responses:
        '202':
          description: The image, being created.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Image'
              examples:
                pending:
                  summary: Being created
                  value:
                    id: 0193c6b2-5a10-7c3d-8e4f-1a2b3c4d5e6f
                    conversation_id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
                    message_id: 0193c6b2-5a0f-7d1e-9f20-3b4c5d6e7f80
                    prompt: 'Cartaz para a promoção de sábado: vestidos a 8.000 Kz, loja no Kilamba.'
                    quality: standard
                    model_name: GPT Image 2
                    status: pending
                    error_code: null
                    cost: null
                    width: 1024
                    height: 1024
                    url: null
                    thumbnail_url: null
                    urls_expire_at: null
                    created_at: '2026-11-21T10:00:00Z'
                    completed_at: null
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
        '503':
          $ref: '#/components/responses/ChatUnavailable'
    get:
      operationId: listImages
      summary: List images
      description: The user's gallery ("Imagens criadas"), newest first, by cursor. Only `ready` images.
      tags:
        - images
      x-stability: beta
      parameters:
        - $ref: '#/components/parameters/Cursor'
        - $ref: '#/components/parameters/Limit'
      responses:
        '200':
          description: A page of images.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImagePage'
              examples:
                page:
                  summary: One image
                  value:
                    next_cursor: null
                    data:
                      - id: 0193c6b2-5a10-7c3d-8e4f-1a2b3c4d5e6f
                        conversation_id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
                        message_id: 0193c6b2-5a0f-7d1e-9f20-3b4c5d6e7f80
                        prompt: 'Cartaz para a promoção de sábado: vestidos a 8.000 Kz, loja no Kilamba.'
                        quality: standard
                        model_name: GPT Image 2
                        status: ready
                        error_code: null
                        cost:
                          amount_cents: 14452
                          currency: AOA
                        width: 1024
                        height: 1024
                        url: https://img.elunyo.example/img/0193c4f8/0193c6b2.jpg?Policy=...
                        thumbnail_url: https://img.elunyo.example/img/0193c4f8/0193c6b2-thumb.webp?Policy=...
                        urls_expire_at: '2026-11-21T10:15:00Z'
                        created_at: '2026-11-21T10:00:00Z'
                        completed_at: '2026-11-21T10:00:21Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/images/{image_id}:
    parameters:
      - $ref: '#/components/parameters/ImageId'
    get:
      operationId: getImage
      summary: Get an image
      description: An image of the user, in any state. Its links are signed again on every read.
      tags:
        - images
      x-stability: beta
      responses:
        '200':
          description: The image.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Image'
              examples:
                failed:
                  summary: Refused by the model's content rules
                  value:
                    id: 0193c6b2-5a10-7c3d-8e4f-1a2b3c4d5e6f
                    conversation_id: 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
                    message_id: 0193c6b2-5a0f-7d1e-9f20-3b4c5d6e7f80
                    prompt: Uma fotografia de uma pessoa famosa.
                    quality: standard
                    model_name: GPT Image 2
                    status: failed
                    error_code: image_refused
                    cost: null
                    width: 1024
                    height: 1024
                    url: null
                    thumbnail_url: null
                    urls_expire_at: null
                    created_at: '2026-11-21T10:00:00Z'
                    completed_at: '2026-11-21T10:00:04Z'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  securitySchemes:
    cookieAuth:
      type: apiKey
      in: cookie
      name: sid
      description: |
        Session of a web app user. The `sid` cookie is set at the end of the
        social login and is `HttpOnly`, `Secure` and `SameSite=Lax`.
    bearerAuth:
      type: http
      scheme: bearer
      description: |
        API key for third-party integrations, in the `sk_live_...` format.
        Keys cannot be created yet. The scheme is declared from the start so
        that authentication accepts both forms.
  schemas:
    Health:
      type: object
      description: Health of one API instance.
      required:
        - status
      properties:
        status:
          type: string
          description: Instance status. `ok` means it accepts requests.
          enum:
            - ok
    Meta:
      type: object
      description: API metadata the web client reads on startup.
      required:
        - api_version
        - min_web_version
      properties:
        api_version:
          type: string
          description: |
            Contract version this instance serves, in semver. It is the
            `info.version` of this document.
          examples:
            - 0.1.0
        min_web_version:
          type: string
          pattern: ^\d+\.\d+\.\d+$
          description: |
            Minimum web client version this API accepts: three numbers separated by
            dots.

            The client compares it with its own version, number by number, ignoring
            anything after a `+`. If it is below, the client forces an update.
            `0.0.0` means there is no minimum.
          examples:
            - 2026.11.15
    Problem:
      type: object
      description: |
        Error in the RFC 9457 format (`application/problem+json`).

        Clients decide what to do and what to show from `code`, translating it in
        the user's language. `title` and `detail` are English text for developers
        and logs, and are never shown to end users.

        Some errors carry extra fields, described in each error's schema. A client
        must ignore fields it does not know.
      required:
        - type
        - title
        - status
        - code
        - request_id
      properties:
        type:
          type: string
          format: uri
          description: URL of the page that documents this error type.
          examples:
            - https://docs.elunyo.app/errors/service_unavailable
        title:
          type: string
          description: |
            Short English summary of the error type. It is the same for every
            occurrence of the same `code`.
          examples:
            - Service unavailable
        status:
          type: integer
          format: int32
          minimum: 400
          maximum: 599
          description: HTTP status code of this response.
          examples:
            - 503
        detail:
          type: string
          description: English explanation of this specific occurrence, for developers and logs.
          examples:
            - The service is restarting. Try again shortly.
        code:
          $ref: '#/components/schemas/ProblemCode'
        request_id:
          type: string
          description: |
            Request id, equal to the `X-Request-ID` response header. Use it to find
            the request in the logs.
          examples:
            - 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    ProblemCode:
      type: string
      description: |
        Stable, machine-readable error code. Clients use it as the translation key
        for the message shown to the user.

        The list is extensible: new codes may be added within v1. A client that
        receives a code it does not know falls back on `status`.

        | Code | Status | When it happens |
        | --- | --- | --- |
        | `validation_failed` | 400 | The request has missing or invalid fields. |
        | `unauthenticated` | 401 | The session or API key is missing or no longer valid. |
        | `insufficient_balance` | 402 | The balance does not cover the hold for this request. |
        | `free_quota_exhausted` | 402 | The free messages for today are used up and there is no balance. |
        | `forbidden` | 403 | The session is valid but cannot perform this operation. |
        | `admin_elevation_required` | 403 | An administrator operation needs the session elevated with the authenticator code. |
        | `otp_invalid` | 400 | The authenticator code is wrong, expired or already used. |
        | `not_found` | 404 | The resource or path does not exist. |
        | `method_not_allowed` | 405 | The path exists but does not accept this method. |
        | `idempotency_conflict` | 409 | The same `Idempotency-Key` was used with a different request. |
        | `last_identity` | 409 | The linked account cannot be removed: it is the only way to sign in. |
        | `generation_in_progress` | 409 | The conversation is still answering the previous message. |
        | `payload_too_large` | 413 | The request body is larger than the endpoint accepts. |
        | `rate_limited` | 429 | Too many requests. See the `Retry-After` header. |
        | `image_refused` | 422 | The image model's content rules refused the prompt. Today it only appears in `Image.error_code`. |
        | `internal_error` | 500 | Unexpected server error. |
        | `model_unavailable` | 503 | The chosen model is unavailable right now. |
        | `service_unavailable` | 503 | The service is overloaded, restarting or without a provider. |
      enum:
        - validation_failed
        - unauthenticated
        - insufficient_balance
        - free_quota_exhausted
        - forbidden
        - admin_elevation_required
        - otp_invalid
        - not_found
        - method_not_allowed
        - idempotency_conflict
        - last_identity
        - generation_in_progress
        - payload_too_large
        - rate_limited
        - image_refused
        - internal_error
        - model_unavailable
        - service_unavailable
    AuthProvider:
      type: string
      description: |
        Social login provider. Google is the only one (ADR 0025).

        | Value | Provider |
        | --- | --- |
        | `google` | Google (OpenID Connect). |
      enum:
        - google
    AuthIntent:
      type: string
      description: |
        What the social login is for.

        | Value | Meaning |
        | --- | --- |
        | `login` | Sign in, or create the account on the first time. |
        | `link` | Link another account to the signed-in user. Needs a session. With Google as the only provider, it ends in `identity_in_use`. |
      enum:
        - login
        - link
    Locale:
      type: string
      description: |
        Language of the web app interface. Extensible.

        | Value | Language |
        | --- | --- |
        | `pt-AO` | Portuguese (Angola). |
        | `en` | English. |
      enum:
        - pt-AO
        - en
    Theme:
      type: string
      description: |
        Interface theme.

        | Value | Meaning |
        | --- | --- |
        | `system` | Follows the device setting. |
        | `light` | Always light. |
        | `dark` | Always dark. |
      enum:
        - system
        - light
        - dark
    ImageQuality:
      type: string
      description: |
        Image quality. Every quality has a fixed price, listed in
        `GET /v1/pricing`.

        | Value | Meaning |
        | --- | --- |
        | `standard` | Good for posts and posters. |
        | `premium` | High quality, for the finest detail. |
      enum:
        - standard
        - premium
    Currency:
      type: string
      description: |
        ISO 4217 currency code. Extensible.

        | Value | Meaning |
        | --- | --- |
        | `AOA` | Angolan kwanza. |
      enum:
        - AOA
    Money:
      type: object
      description: |
        An amount of money in integer cents of a currency. The API never sends
        formatted text: clients format the amount in the user's language.
      required:
        - amount_cents
        - currency
      properties:
        amount_cents:
          type: integer
          format: int64
          description: Amount in cents (1 kwanza = 100 cents). Never a float.
          examples:
            - 1130
        currency:
          $ref: '#/components/schemas/Currency'
    Preferences:
      type: object
      description: User preferences, saved on the account and applied on every device.
      required:
        - theme
        - default_model_id
        - image_quality
        - confirm_expensive
        - confirm_above
        - low_balance_alert
        - low_balance_threshold
        - retention_days
      properties:
        theme:
          $ref: '#/components/schemas/Theme'
        default_model_id:
          type:
            - string
            - 'null'
          description: |
            Model chosen for new conversations. `null` means the first model of the
            free group.
          examples:
            - gemini-2.5-flash-lite
        image_quality:
          $ref: '#/components/schemas/ImageQuality'
        confirm_expensive:
          type: boolean
          description: Ask for confirmation before sending a message estimated above `confirm_above`.
          examples:
            - true
        confirm_above:
          $ref: '#/components/schemas/Money'
        low_balance_alert:
          type: boolean
          description: Warn when the balance falls below `low_balance_threshold`.
          examples:
            - true
        low_balance_threshold:
          $ref: '#/components/schemas/Money'
        retention_days:
          type: integer
          format: int32
          description: |
            Days conversations are kept before they are deleted. One of 30, 90, 180
            or 365.
          enum:
            - 30
            - 90
            - 180
            - 365
          examples:
            - 90
    User:
      type: object
      description: The signed-in user, with their preferences.
      required:
        - id
        - name
        - email
        - avatar_url
        - locale
        - created_at
        - is_new
        - preferences
      properties:
        id:
          type: string
          format: uuid
          description: User id.
          examples:
            - 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
        name:
          type: string
          description: Display name, from the provider or edited by the user.
          examples:
            - Ana Domingos
        email:
          type:
            - string
            - 'null'
          format: email
          description: Email verified by a provider. `null` when no provider gave one.
          examples:
            - ana.domingos@example.com
        avatar_url:
          type:
            - string
            - 'null'
          format: uri
          description: Profile picture from the provider, if any.
          examples:
            - https://lh3.googleusercontent.com/a/example
        locale:
          $ref: '#/components/schemas/Locale'
        created_at:
          type: string
          format: date-time
          description: When the account was created.
          examples:
            - '2026-10-02T09:15:00Z'
        is_new:
          type: boolean
          description: |
            True on the first sign-in. The web app uses it to say there are free
            messages every day.
          examples:
            - false
        preferences:
          $ref: '#/components/schemas/Preferences'
    PreferencesUpdate:
      type: object
      description: Preferences to change. Fields left out keep their value.
      properties:
        theme:
          $ref: '#/components/schemas/Theme'
        default_model_id:
          type: string
          minLength: 1
          maxLength: 64
          description: Id of an enabled model, from `GET /v1/models`.
          examples:
            - sonnet-5.5
        image_quality:
          $ref: '#/components/schemas/ImageQuality'
        confirm_expensive:
          type: boolean
          description: Ask for confirmation before sending an expensive message.
          examples:
            - false
        low_balance_alert:
          type: boolean
          description: Warn when the balance is low.
          examples:
            - true
        retention_days:
          type: integer
          format: int32
          description: Days conversations are kept. One of 30, 90, 180 or 365.
          enum:
            - 30
            - 90
            - 180
            - 365
          examples:
            - 180
    UpdateMeRequest:
      type: object
      description: Profile fields to change. Fields left out keep their value.
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 80
          description: New display name. Leading and trailing spaces are removed.
          examples:
            - Ana Domingos
        locale:
          $ref: '#/components/schemas/Locale'
        preferences:
          $ref: '#/components/schemas/PreferencesUpdate'
    Quota:
      type: object
      description: Free messages of the current day (Africa/Luanda).
      required:
        - limit
        - used
        - remaining
        - resets_at
      properties:
        limit:
          type: integer
          format: int32
          description: Free messages per day. Configuration, not a constant.
          examples:
            - 20
        used:
          type: integer
          format: int32
          description: Free messages used today.
          examples:
            - 3
        remaining:
          type: integer
          format: int32
          description: Free messages left today.
          examples:
            - 17
        resets_at:
          type: string
          format: date-time
          description: Next midnight in Luanda, when the quota resets.
          examples:
            - '2026-11-20T23:00:00Z'
    DataExportStatus:
      type: string
      description: |
        State of an export of the user's data.

        | Value | Meaning |
        | --- | --- |
        | `preparing` | The worker is building the file. Ask again in a few seconds. |
        | `ready` | `url` downloads the file until `expires_at`. |
        | `failed` | The file could not be built. A new request is allowed at once. |
        | `expired` | The file was deleted 24 hours after it was ready. |
      enum:
        - preparing
        - ready
        - failed
        - expired
    DataExport:
      type: object
      description: |
        A file with the user's data: a ZIP with the data in JSON and the images.
      required:
        - id
        - status
        - created_at
        - ready_at
        - expires_at
        - size_bytes
        - url
        - next_request_at
      properties:
        id:
          type: string
          format: uuid
          description: Export id.
          examples:
            - 0193d1a0-2b3c-7d4e-8f50-6a7b8c9d0e1f
        status:
          $ref: '#/components/schemas/DataExportStatus'
        created_at:
          type: string
          format: date-time
          description: When the user asked for it.
          examples:
            - '2026-11-21T14:00:00Z'
        ready_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When the file was ready; null before.
          examples:
            - '2026-11-21T14:00:40Z'
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
          description: Until when `url` works and the file exists (24 hours after `ready_at`); null before it is ready.
          examples:
            - '2026-11-22T14:00:40Z'
        size_bytes:
          type:
            - integer
            - 'null'
          format: int64
          minimum: 0
          description: Size of the file; null before it is ready.
          examples:
            - 3481920
        url:
          type:
            - string
            - 'null'
          format: uri
          description: Signed link that downloads the file, only while `status` is `ready`.
          examples:
            - https://img.elunyo.example/exports/u/x.zip?Signature=y
        next_request_at:
          type: string
          format: date-time
          description: From when a new export may be requested (24 hours after this one, or now if it failed).
          examples:
            - '2026-11-22T14:00:00Z'
    Identity:
      type: object
      description: A social account linked to the user.
      required:
        - provider
        - email
        - created_at
      properties:
        provider:
          $ref: '#/components/schemas/AuthProvider'
        email:
          type:
            - string
            - 'null'
          format: email
          description: Email of that account, when the provider shares it.
          examples:
            - ana.domingos@example.com
        created_at:
          type: string
          format: date-time
          description: When the account was linked.
          examples:
            - '2026-10-02T09:15:00Z'
    IdentityList:
      type: object
      description: Social accounts linked to the user.
      required:
        - data
      properties:
        data:
          type: array
          description: Linked accounts, oldest first.
          items:
            $ref: '#/components/schemas/Identity'
    ModelGroup:
      type: string
      description: |
        Catalog group shown in the model picker. Extensible.

        | Value | Meaning |
        | --- | --- |
        | `free` | Covered by the daily free messages. |
        | `fast` | Fast and cheap. |
        | `strong` | Most capable. |
      enum:
        - free
        - fast
        - strong
    LocalizedText:
      type: object
      description: A short text in every interface language. Clients show the one of the current language.
      required:
        - pt_ao
        - en
      properties:
        pt_ao:
          type: string
          description: Portuguese (Angola).
          examples:
            - Textos, trabalho e código
        en:
          type: string
          description: English.
          examples:
            - Writing, work and code
    Model:
      type: object
      description: |
        A text model of the catalog, with prices computed from the current list
        prices, exchange rate and plan parameters.
      required:
        - id
        - display_name
        - maker
        - group
        - description
        - data_location
        - free_eligible
        - available
        - short_message_price
        - price_per_mtok_in
        - price_per_mtok_out
        - context_window
        - max_output_tokens
      properties:
        id:
          type: string
          description: Stable model id used by this API.
          examples:
            - sonnet-5.5
        display_name:
          type: string
          description: Name shown to users.
          examples:
            - Sonnet 5.5
        maker:
          type: string
          description: Company that makes the model.
          examples:
            - Anthropic
        group:
          $ref: '#/components/schemas/ModelGroup'
        description:
          $ref: '#/components/schemas/LocalizedText'
        data_location:
          type:
            - string
            - 'null'
          description: |
            ISO 3166-1 alpha-2 code of the country where the provider processes the
            data, when users should be told (for example `CN`). `null` otherwise.
          examples:
            - CN
        free_eligible:
          type: boolean
          description: Messages to this model use the daily free quota while it lasts.
          examples:
            - false
        available:
          type: boolean
          description: False when the model cannot answer right now. The picker shows it disabled.
          examples:
            - true
        short_message_price:
          $ref: '#/components/schemas/Money'
        price_per_mtok_in:
          $ref: '#/components/schemas/Money'
        price_per_mtok_out:
          $ref: '#/components/schemas/Money'
        context_window:
          type: integer
          format: int32
          description: Maximum tokens of context the model accepts.
          examples:
            - 200000
        max_output_tokens:
          type: integer
          format: int32
          description: Maximum tokens of one answer.
          examples:
            - 8192
    ModelList:
      type: object
      description: Catalog of text models, in display order.
      required:
        - data
        - pricing_version
      properties:
        data:
          type: array
          description: Enabled models, grouped and sorted for the picker.
          items:
            $ref: '#/components/schemas/Model'
        pricing_version:
          type: string
          description: Version of the prices used. Changes whenever a price, the exchange rate or a plan parameter changes.
          examples:
            - pv_9f2c1a7e
    RechargeYield:
      type: object
      description: How many short messages a recharge buys in one model.
      required:
        - model_id
        - display_name
        - messages
      properties:
        model_id:
          type: string
          description: Model id.
          examples:
            - sonnet-5.5
        display_name:
          type: string
          description: Model name shown to users.
          examples:
            - Sonnet 5.5
        messages:
          type: integer
          format: int64
          description: Short messages the amount buys, rounded down.
          examples:
            - 88
    ImageYield:
      type: object
      description: How many images of one quality a recharge buys.
      required:
        - quality
        - images
      properties:
        quality:
          $ref: '#/components/schemas/ImageQuality'
        images:
          type: integer
          format: int64
          description: Images the amount buys, rounded down.
          examples:
            - 8
    RechargeOption:
      type: object
      description: A recharge amount offered in the app, with what it buys in the featured models and in images.
      required:
        - amount
        - iva
        - featured
        - yields
        - image_yields
      properties:
        amount:
          $ref: '#/components/schemas/Money'
        iva:
          $ref: '#/components/schemas/Money'
        featured:
          type: boolean
          description: The amount highlighted on the sign-in screen and the landing page.
          examples:
            - true
        yields:
          type: array
          description: Short messages per featured model, in catalog order.
          items:
            $ref: '#/components/schemas/RechargeYield'
        image_yields:
          type: array
          description: |
            Images per quality, for every quality of `image_qualities` in
            `GET /v1/pricing` and in the same order, available or not: clients
            check `available` there.
          items:
            $ref: '#/components/schemas/ImageYield'
    PaymentMethod:
      type: string
      description: |
        How a recharge is paid. The list is extensible.

        | Value | Meaning |
        | --- | --- |
        | `multicaixa_express` | A payment request sent to the phone, accepted in the Multicaixa Express app. |
        | `reference` | An entity and a reference, paid at an ATM or in internet banking. |
      enum:
        - multicaixa_express
        - reference
    ImageTier:
      type: object
      description: An image quality with its price.
      required:
        - quality
        - model_name
        - price
        - width
        - height
        - available
      properties:
        quality:
          $ref: '#/components/schemas/ImageQuality'
        model_name:
          type: string
          description: Image model of this quality.
          examples:
            - GPT Image 2
        price:
          $ref: '#/components/schemas/Money'
        width:
          type: integer
          format: int32
          description: Width of the images, in pixels.
          examples:
            - 1024
        height:
          type: integer
          format: int32
          description: Height of the images, in pixels.
          examples:
            - 1024
        available:
          type: boolean
          description: The quality can be used now. When `false`, clients disable it.
          examples:
            - true
    Pricing:
      type: object
      description: Public pricing summary for the sign-in screen, the paywall, the composer and the landing page.
      required:
        - pricing_version
        - updated_at
        - free_daily_messages
        - recharge_options
        - recharge_min
        - recharge_max
        - payment_methods
        - image_qualities
      properties:
        pricing_version:
          type: string
          description: Version of the prices used.
          examples:
            - pv_9f2c1a7e
        updated_at:
          type: string
          format: date-time
          description: When the current prices took effect.
          examples:
            - '2026-11-01T00:00:00Z'
        free_daily_messages:
          type: integer
          format: int32
          description: Free messages per day.
          examples:
            - 20
        recharge_options:
          type: array
          description: Recharge amounts, smallest first. The first is the minimum.
          items:
            $ref: '#/components/schemas/RechargeOption'
        recharge_min:
          $ref: '#/components/schemas/Money'
        recharge_max:
          $ref: '#/components/schemas/Money'
        payment_methods:
          type: array
          description: Ways to pay a recharge, in the order to show them.
          items:
            $ref: '#/components/schemas/PaymentMethod'
        image_qualities:
          type: array
          description: Image qualities and their prices, cheapest first.
          items:
            $ref: '#/components/schemas/ImageTier'
    Conversation:
      type: object
      description: A conversation of the user.
      required:
        - id
        - title
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
          description: Conversation id.
          examples:
            - 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
        title:
          type: string
          description: Title. Taken from the first message until the user renames it.
          examples:
            - Cartaz da promoção de sábado
        created_at:
          type: string
          format: date-time
          description: When it was created.
          examples:
            - '2026-11-20T08:12:00Z'
        updated_at:
          type: string
          format: date-time
          description: Last message or rename. The list is sorted by this field, newest first.
          examples:
            - '2026-11-20T08:20:31Z'
    ConversationPage:
      type: object
      description: A page of conversations, newest first.
      required:
        - data
        - next_cursor
      properties:
        data:
          type: array
          description: Conversations of this page.
          items:
            $ref: '#/components/schemas/Conversation'
        next_cursor:
          type:
            - string
            - 'null'
          description: Cursor of the next page. `null` on the last page.
          examples:
            - eyJ0IjoiMjAyNi0xMS0yMFQwODoyMDozMVoiLCJpZCI6IjAxOTMifQ
    CreateConversationRequest:
      type: object
      description: A new, empty conversation.
      properties:
        title:
          type: string
          minLength: 1
          maxLength: 120
          description: Optional title. Without it, the first message gives the title.
          examples:
            - Plano de aulas
    UpdateConversationRequest:
      type: object
      description: New title of a conversation.
      required:
        - title
      properties:
        title:
          type: string
          minLength: 1
          maxLength: 120
          description: New title. Leading and trailing spaces are removed.
          examples:
            - Legendas para o Instagram
    MessageRole:
      type: string
      description: |
        Author of a message.

        | Value | Meaning |
        | --- | --- |
        | `user` | Written by the user. |
        | `assistant` | Answer of a model. |
      enum:
        - user
        - assistant
    MessageKind:
      type: string
      description: |
        What a message holds. The list is extensible.

        | Value | Meaning |
        | --- | --- |
        | `text` | A text message or a text answer. |
        | `image` | A request for an image, or the answer that shows it (see `image`). |
      enum:
        - text
        - image
    MessageStatus:
      type: string
      description: |
        State of a message. User messages are always `done`.

        | Value | Meaning |
        | --- | --- |
        | `streaming` | The answer is being generated. Follow a `text` answer with `GET /v1/messages/{id}/stream`; an `image` answer with `GET /v1/images/{image_id}`. |
        | `done` | Complete. |
        | `failed` | The model failed. Any partial text is kept and nothing was charged. |
        | `canceled` | Stopped by the user or abandoned. Only the delivered tokens count. |
      enum:
        - streaming
        - done
        - failed
        - canceled
    Funding:
      type: string
      description: |
        What pays for an answer.

        | Value | Meaning |
        | --- | --- |
        | `free` | One of the daily free messages. |
        | `wallet` | The user's balance. |
      enum:
        - free
        - wallet
    ImageStatus:
      type: string
      description: |
        State of an image.

        | Value | Meaning |
        | --- | --- |
        | `pending` | Being created. Poll `GET /v1/images/{image_id}` every 1.5 seconds. |
        | `ready` | Created, stored and charged. `url` and `thumbnail_url` are set. |
        | `failed` | Not created (`error_code` says why). Nothing was charged. |
      enum:
        - pending
        - ready
        - failed
    Image:
      type: object
      description: |
        An image created from a prompt. It belongs to a conversation, where its
        answer message shows it, and to the gallery once it is `ready`.
      required:
        - id
        - conversation_id
        - message_id
        - prompt
        - quality
        - model_name
        - status
        - error_code
        - cost
        - width
        - height
        - url
        - thumbnail_url
        - urls_expire_at
        - created_at
        - completed_at
      properties:
        id:
          type: string
          format: uuid
          description: Image id.
          examples:
            - 0193c6b2-5a10-7c3d-8e4f-1a2b3c4d5e6f
        conversation_id:
          type: string
          format: uuid
          description: Conversation the image belongs to.
          examples:
            - 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
        message_id:
          type: string
          format: uuid
          description: The answer message that shows the image in the conversation.
          examples:
            - 0193c6b2-5a0f-7d1e-9f20-3b4c5d6e7f80
        prompt:
          type: string
          description: What the user asked for.
          examples:
            - 'Cartaz para a promoção de sábado: vestidos a 8.000 Kz, loja no Kilamba.'
        quality:
          $ref: '#/components/schemas/ImageQuality'
        model_name:
          type: string
          description: Name of the image model, to show next to the image.
          examples:
            - GPT Image 2
        status:
          $ref: '#/components/schemas/ImageStatus'
        error_code:
          oneOf:
            - $ref: '#/components/schemas/ProblemCode'
            - type: 'null'
          description: |
            Why a `failed` image failed: `image_refused` (the model's content
            rules refused the prompt), `model_unavailable` or `service_unavailable`.
        cost:
          oneOf:
            - $ref: '#/components/schemas/Money'
            - type: 'null'
          description: Amount charged to the balance. `null` unless `ready`.
        width:
          type: integer
          format: int32
          description: Width in pixels.
          examples:
            - 1024
        height:
          type: integer
          format: int32
          description: Height in pixels.
          examples:
            - 1024
        url:
          type:
            - string
            - 'null'
          format: uri
          description: |
            The full image (JPEG), on a signed link valid until `urls_expire_at`.
            Opening it downloads the file. `null` unless `ready`.
          examples:
            - https://img.elunyo.example/img/0193c4f8/0193c6b2.jpg?Policy=...
        thumbnail_url:
          type:
            - string
            - 'null'
          format: uri
          description: A smaller copy (WebP, 512 pixels wide) for lists and cards, signed like `url`. `null` unless `ready`.
          examples:
            - https://img.elunyo.example/img/0193c4f8/0193c6b2-thumb.webp?Policy=...
        urls_expire_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When `url` and `thumbnail_url` stop working; read the image again for new links. `null` unless `ready`.
          examples:
            - '2026-11-21T10:15:00Z'
        created_at:
          type: string
          format: date-time
          description: When it was asked for.
          examples:
            - '2026-11-21T10:00:00Z'
        completed_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When it became `ready` or `failed`.
          examples:
            - '2026-11-21T10:00:21Z'
    Message:
      type: object
      description: A message of a conversation.
      required:
        - id
        - conversation_id
        - role
        - kind
        - content
        - model_id
        - status
        - funding
        - cost
        - error_code
        - truncated
        - image
        - created_at
        - completed_at
      properties:
        id:
          type: string
          format: uuid
          description: Message id.
          examples:
            - 0193c4f9-1d2e-7a3b-8c4d-5e6f7a8b9c0d
        conversation_id:
          type: string
          format: uuid
          description: Conversation id.
          examples:
            - 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
        role:
          $ref: '#/components/schemas/MessageRole'
        kind:
          $ref: '#/components/schemas/MessageKind'
        content:
          type: string
          description: |
            Text in Markdown. For a `streaming` answer, the text saved so far may
            be empty. For an `image` request it is the prompt; an `image` answer
            has no text.
          examples:
            - Sábado é dia de vestido novo.
        model_id:
          type:
            - string
            - 'null'
          description: Model that answered. `null` on user messages and on `image` answers (see `image.model_name`).
          examples:
            - sonnet-5.5
        status:
          $ref: '#/components/schemas/MessageStatus'
        funding:
          oneOf:
            - $ref: '#/components/schemas/Funding'
            - type: 'null'
          description: What paid for the answer. `null` on user messages.
        cost:
          oneOf:
            - $ref: '#/components/schemas/Money'
            - type: 'null'
          description: Amount charged to the balance. Zero for free answers, `null` while streaming and on user messages.
        error_code:
          oneOf:
            - $ref: '#/components/schemas/ProblemCode'
            - type: 'null'
          description: Why a `failed` answer failed.
        truncated:
          type: boolean
          description: The answer stopped at the length the balance could pay for.
          examples:
            - false
        image:
          oneOf:
            - $ref: '#/components/schemas/Image'
            - type: 'null'
          description: The image of an `image` answer. `null` on every other message.
        created_at:
          type: string
          format: date-time
          description: When it was created.
          examples:
            - '2026-11-20T08:20:31Z'
        completed_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When the answer finished. `null` while streaming.
          examples:
            - '2026-11-20T08:20:39Z'
    MessagePage:
      type: object
      description: A page of messages, newest first. Clients show them oldest first.
      required:
        - data
        - next_cursor
      properties:
        data:
          type: array
          description: Messages of this page.
          items:
            $ref: '#/components/schemas/Message'
        next_cursor:
          type:
            - string
            - 'null'
          description: Cursor of the page of older messages. `null` when there are no more.
          examples:
            - eyJ0IjoiMjAyNi0xMS0yMFQwODoyMDozMVoiLCJpZCI6IjAxOTMifQ
    SendMessageRequest:
      type: object
      description: A user message to send to a model.
      required:
        - model_id
        - content
        - client_message_id
      properties:
        model_id:
          type: string
          minLength: 1
          maxLength: 64
          description: Id of an enabled model, from `GET /v1/models`.
          examples:
            - gemini-2.5-flash-lite
        content:
          type: string
          minLength: 1
          maxLength: 32768
          description: Message text, at most 32 KB once encoded in UTF-8.
          examples:
            - Ajuda-me a escrever o resumo do meu CV.
        client_message_id:
          type: string
          format: uuid
          description: |
            Id the client generates once per message. Sending the same id again
            (after a lost connection) does not create a second message: the
            answer already started is streamed instead.
          examples:
            - 6f1c2b3a-4d5e-4f60-8a7b-9c0d1e2f3a4b
    ChatEventType:
      type: string
      description: |
        Type of a chat stream event. It is also the SSE `event` field. Extensible:
        clients ignore types they do not know.

        | Value | Meaning |
        | --- | --- |
        | `meta` | First event: ids, model and what pays. |
        | `delta` | A piece of the answer text, to append. |
        | `done` | The answer is complete or was stopped. Last event. |
        | `error` | The answer failed. Last event. |
      enum:
        - meta
        - delta
        - done
        - error
    ChatMetaEvent:
      type: object
      description: First event of a stream.
      required:
        - type
        - message_id
        - user_message_id
        - conversation_id
        - model_id
        - funding
      properties:
        type:
          $ref: '#/components/schemas/ChatEventType'
        message_id:
          type: string
          format: uuid
          description: Id of the answer.
          examples:
            - 0193c4f9-1d2e-7a3b-8c4d-5e6f7a8b9c0d
        user_message_id:
          type: string
          format: uuid
          description: Id of the user message that was saved.
          examples:
            - 0193c4f9-1d2d-7f00-9a1b-2c3d4e5f6a7b
        conversation_id:
          type: string
          format: uuid
          description: Conversation id.
          examples:
            - 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
        model_id:
          type: string
          description: Model that answers.
          examples:
            - gemini-2.5-flash-lite
        funding:
          $ref: '#/components/schemas/Funding'
    ChatDeltaEvent:
      type: object
      description: A piece of answer text. Append it to what arrived before.
      required:
        - type
        - text
      properties:
        type:
          $ref: '#/components/schemas/ChatEventType'
        text:
          type: string
          description: Text to append.
          examples:
            - O contrato dura 12 meses
    ChatDoneEvent:
      type: object
      description: Last event of a completed or stopped answer.
      required:
        - type
        - message_id
        - status
        - cost
        - input_tokens
        - output_tokens
        - quota_remaining
        - balance
        - truncated
      properties:
        type:
          $ref: '#/components/schemas/ChatEventType'
        message_id:
          type: string
          format: uuid
          description: Id of the answer.
          examples:
            - 0193c4f9-1d2e-7a3b-8c4d-5e6f7a8b9c0d
        status:
          $ref: '#/components/schemas/MessageStatus'
        cost:
          $ref: '#/components/schemas/Money'
        input_tokens:
          type: integer
          format: int32
          description: Input tokens counted by the provider.
          examples:
            - 812
        output_tokens:
          type: integer
          format: int32
          description: Output tokens counted by the provider.
          examples:
            - 264
        quota_remaining:
          type:
            - integer
            - 'null'
          format: int32
          description: Free messages left today after this answer. `null` when the answer was paid from the balance.
          examples:
            - 16
        balance:
          oneOf:
            - $ref: '#/components/schemas/Money'
            - type: 'null'
          description: Balance after this answer. `null` when a free message paid for it.
        truncated:
          type: boolean
          description: |
            The answer stopped at the length the balance could pay for. Clients
            say so under the answer.
          examples:
            - false
    ChatErrorEvent:
      type: object
      description: |
        Last event of an answer that failed. Nothing is charged, and a free
        message used for it is given back. Any text already delivered stays.
      required:
        - type
        - message_id
        - code
        - status
      properties:
        type:
          $ref: '#/components/schemas/ChatEventType'
        message_id:
          type: string
          format: uuid
          description: Id of the answer.
          examples:
            - 0193c4f9-1d2e-7a3b-8c4d-5e6f7a8b9c0d
        code:
          $ref: '#/components/schemas/ProblemCode'
        status:
          type: integer
          format: int32
          description: HTTP status that the same error has as a problem response.
          examples:
            - 503
    ChatStreamEvent:
      description: |
        Data of one event of a chat stream (`text/event-stream`).

        Each event is sent as `id: <n>`, `event: <type>` and `data: <JSON>`. The
        `id` grows by one per event; send the last one received in the
        `Last-Event-ID` header of `GET /v1/messages/{id}/stream` to resume after a
        lost connection. A comment line (`: ping`) arrives every 15 seconds to keep
        the connection open.
      oneOf:
        - $ref: '#/components/schemas/ChatMetaEvent'
        - $ref: '#/components/schemas/ChatDeltaEvent'
        - $ref: '#/components/schemas/ChatDoneEvent'
        - $ref: '#/components/schemas/ChatErrorEvent'
      discriminator:
        propertyName: type
        mapping:
          meta: '#/components/schemas/ChatMetaEvent'
          delta: '#/components/schemas/ChatDeltaEvent'
          done: '#/components/schemas/ChatDoneEvent'
          error: '#/components/schemas/ChatErrorEvent'
    PaymentRequiredProblem:
      description: |
        Problem of a 402 answer. With `insufficient_balance`, `needed` and
        `balance` say how much is missing. With `free_quota_exhausted`, `limit`
        and `resets_at` say when free messages come back.
      allOf:
        - $ref: '#/components/schemas/Problem'
        - type: object
          properties:
            needed:
              $ref: '#/components/schemas/Money'
            balance:
              $ref: '#/components/schemas/Money'
            limit:
              type: integer
              format: int32
              description: Free messages per day.
              examples:
                - 20
            resets_at:
              type: string
              format: date-time
              description: Next midnight in Luanda.
              examples:
                - '2026-11-20T23:00:00Z'
    ModelUnavailableProblem:
      description: |
        Problem of a `model_unavailable` answer, with other models of the same
        group that can answer now.
      allOf:
        - $ref: '#/components/schemas/Problem'
        - type: object
          properties:
            alternatives:
              type: array
              description: Ids of available models of the same group.
              items:
                type: string
                examples:
                  - deepseek-v4.1-flash
    EstimateRequest:
      type: object
      description: A message to estimate before sending it.
      required:
        - model_id
        - content
      properties:
        model_id:
          type: string
          minLength: 1
          maxLength: 64
          description: Id of an enabled model, from `GET /v1/models`.
          examples:
            - sonnet-5.5
        content:
          type: string
          maxLength: 32768
          description: Text about to be sent. May be empty, to estimate the conversation alone.
          examples:
            - Resume este contrato em cinco pontos.
        conversation_id:
          type:
            - string
            - 'null'
          format: uuid
          description: Conversation the message goes to. Its history counts in the estimate. Leave out for a new conversation.
          examples:
            - 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
    Estimate:
      type: object
      description: |
        What a message would cost: the history that fits in the model's context,
        the text, and an answer of the size of a short message. The real cost
        depends on the answer's length.
      required:
        - model_id
        - funding
        - cost
        - confirm
        - balance
      properties:
        model_id:
          type: string
          description: Model of the estimate.
          examples:
            - sonnet-5.5
        funding:
          $ref: '#/components/schemas/Funding'
        cost:
          $ref: '#/components/schemas/Money'
        confirm:
          type: boolean
          description: |
            The user asked to confirm messages above their threshold, and this one
            is above it. Clients ask before sending.
          examples:
            - true
        balance:
          $ref: '#/components/schemas/Money'
    RechargeQuote:
      type: object
      description: What a recharge amount includes and buys.
      required:
        - amount
        - iva
        - yields
        - image_yields
      properties:
        amount:
          $ref: '#/components/schemas/Money'
        iva:
          $ref: '#/components/schemas/Money'
        yields:
          type: array
          description: Short messages per featured model, in catalog order.
          items:
            $ref: '#/components/schemas/RechargeYield'
        image_yields:
          type: array
          description: |
            Images per quality, for every quality of `image_qualities` in
            `GET /v1/pricing` and in the same order, available or not: clients
            check `available` there.
          items:
            $ref: '#/components/schemas/ImageYield'
    MonthSpending:
      type: object
      description: What the balance paid in the current month, in Luanda time.
      required:
        - month
        - total
        - conversations
        - images
      properties:
        month:
          type: string
          pattern: ^[0-9]{4}-[0-9]{2}$
          description: Month, as `YYYY-MM`.
          examples:
            - 2026-11
        total:
          $ref: '#/components/schemas/Money'
        conversations:
          $ref: '#/components/schemas/Money'
        images:
          $ref: '#/components/schemas/Money'
    Wallet:
      type: object
      description: Balance of the signed-in user.
      required:
        - balance
        - held
        - low_balance
        - last_phone
        - month_spending
        - yields
      properties:
        balance:
          $ref: '#/components/schemas/Money'
        held:
          $ref: '#/components/schemas/Money'
        low_balance:
          type: boolean
          description: |
            The balance is below the user's low-balance threshold and the alert is
            on. Clients show the low-balance notice.
          examples:
            - false
        last_phone:
          type:
            - string
            - 'null'
          description: Number of the last Multicaixa Express payment, to fill in the next one.
          examples:
            - '923456567'
        month_spending:
          $ref: '#/components/schemas/MonthSpending'
        yields:
          type: array
          description: Short messages the balance buys in each featured model, in catalog order.
          items:
            $ref: '#/components/schemas/RechargeYield'
    TransactionKind:
      type: string
      description: |
        Kind of a statement line. The list is extensible.

        | Value | Meaning |
        | --- | --- |
        | `top_up` | A paid recharge. |
        | `conversation` | Answers of one conversation on one day, added up. |
        | `image` | Images of one day, added up. |
        | `adjustment` | A correction made by the team. |
      enum:
        - top_up
        - conversation
        - image
        - adjustment
    Transaction:
      type: object
      description: A line of the statement. Answers are added up per conversation and day.
      required:
        - id
        - kind
        - amount
        - title
        - conversation_id
        - payment_method
        - count
        - occurred_at
      properties:
        id:
          type: string
          format: uuid
          description: Line id.
          examples:
            - 0193c5a1-0c1d-7e2f-8a3b-4c5d6e7f8a9b
        kind:
          $ref: '#/components/schemas/TransactionKind'
        amount:
          $ref: '#/components/schemas/Money'
        title:
          type:
            - string
            - 'null'
          description: Title of the conversation. `null` for other kinds, or when the conversation was deleted.
          examples:
            - Resumo do contrato
        conversation_id:
          type:
            - string
            - 'null'
          format: uuid
          description: Conversation of a `conversation` line, while it exists.
          examples:
            - 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
        payment_method:
          oneOf:
            - $ref: '#/components/schemas/PaymentMethod'
            - type: 'null'
          description: How a `top_up` was paid. `null` for other kinds.
        count:
          type: integer
          format: int32
          description: Answers or images added up in the line. 1 for other kinds.
          examples:
            - 3
        occurred_at:
          type: string
          format: date-time
          description: Time of the last movement of the line.
          examples:
            - '2026-11-12T18:52:00Z'
    TransactionPage:
      type: object
      description: A page of statement lines, newest first.
      required:
        - data
        - next_cursor
      properties:
        data:
          type: array
          description: Lines of this page.
          items:
            $ref: '#/components/schemas/Transaction'
        next_cursor:
          type:
            - string
            - 'null'
          description: Cursor of the next page. `null` on the last page.
          examples:
            - eyJ0IjoiMjAyNi0xMS0xMlQxODo1MjowMFoifQ
    CreatePaymentRequest:
      type: object
      description: A recharge to start.
      required:
        - amount_cents
        - method
      properties:
        amount_cents:
          type: integer
          format: int64
          minimum: 1
          description: |
            Amount to recharge, in cents, IVA included. Between `recharge_min` and
            `recharge_max` of `GET /v1/pricing`.
          examples:
            - 100000
        method:
          $ref: '#/components/schemas/PaymentMethod'
        phone:
          type:
            - string
            - 'null'
          maxLength: 20
          description: |
            Angolan mobile number for `multicaixa_express`: 9 digits starting with
            9. Spaces and the +244 prefix are accepted. Left out for `reference`.
          examples:
            - 923 456 567
    PaymentStatus:
      type: string
      description: |
        State of a payment. Only `pending` changes; the others are final, except
        that a late confirmation from the gateway still turns any of them into
        `paid`, because the money was received.

        | Value | Meaning |
        | --- | --- |
        | `pending` | Waiting for the user to pay. |
        | `paid` | Confirmed by the gateway; the balance was credited. |
        | `expired` | Not paid before `expires_at`. |
        | `failed` | Refused by the bank or the gateway. |
        | `canceled` | Canceled by the user. |
      enum:
        - pending
        - paid
        - expired
        - failed
        - canceled
    PaymentInstructions:
      type: object
      description: |
        What the user does to pay. With `multicaixa_express`, `phone` is the
        number the request went to, partly hidden. With `reference`, `entity` and
        `reference` are the values to type at the ATM or in internet banking.
      required:
        - phone
        - entity
        - reference
      properties:
        phone:
          type:
            - string
            - 'null'
          description: Phone number the request went to, with the middle digits hidden.
          examples:
            - 923 ••• 567
        entity:
          type:
            - string
            - 'null'
          description: Entity of the reference payment.
          examples:
            - '00000'
        reference:
          type:
            - string
            - 'null'
          description: Reference to pay, in groups of three digits.
          examples:
            - 123 456 789
    Payment:
      type: object
      description: A recharge of the balance.
      required:
        - id
        - status
        - method
        - amount
        - iva
        - balance_after
        - instructions
        - expires_at
        - paid_at
        - created_at
      properties:
        id:
          type: string
          format: uuid
          description: Payment id.
          examples:
            - 0193c5a0-4b1c-7d2e-9f30-1a2b3c4d5e6f
        status:
          $ref: '#/components/schemas/PaymentStatus'
        method:
          $ref: '#/components/schemas/PaymentMethod'
        amount:
          $ref: '#/components/schemas/Money'
        iva:
          $ref: '#/components/schemas/Money'
        balance_after:
          $ref: '#/components/schemas/Money'
        instructions:
          $ref: '#/components/schemas/PaymentInstructions'
        expires_at:
          type: string
          format: date-time
          description: When a pending payment expires.
          examples:
            - '2026-11-21T10:05:00Z'
        paid_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When the gateway confirmed the payment. `null` until then.
          examples:
            - '2026-11-21T10:01:12Z'
        created_at:
          type: string
          format: date-time
          description: When the payment was created.
          examples:
            - '2026-11-21T10:00:00Z'
    ImagePage:
      type: object
      description: A page of the gallery, newest first.
      required:
        - data
        - next_cursor
      properties:
        data:
          type: array
          description: Images of this page, all `ready`.
          items:
            $ref: '#/components/schemas/Image'
        next_cursor:
          type:
            - string
            - 'null'
          description: Cursor of the page of older images. `null` when there are no more.
          examples:
            - eyJ0IjoiMjAyNi0xMS0yMFQwODoyMDozMVoiLCJpZCI6IjAxOTMifQ
    CreateImageRequest:
      type: object
      description: An image to create.
      required:
        - prompt
        - quality
      properties:
        prompt:
          type: string
          minLength: 1
          maxLength: 4000
          description: What to draw. Sent to the image model as written.
          examples:
            - 'Cartaz para a promoção de sábado: vestidos a 8.000 Kz, loja no Kilamba.'
        quality:
          $ref: '#/components/schemas/ImageQuality'
        conversation_id:
          type: string
          format: uuid
          description: Conversation to add the image to. Leave out to start a new conversation.
          examples:
            - 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
  responses:
    InternalError:
      description: |
        Unexpected server error. The `request_id` lets you find the request in the
        logs.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            internalError:
              summary: Unexpected error
              value:
                type: https://docs.elunyo.app/errors/internal_error
                title: Internal error
                status: 500
                detail: An unexpected error occurred.
                code: internal_error
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    ServiceUnavailable:
      description: |
        The service cannot handle the request right now. The `Retry-After` header
        says when it is worth trying again.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            shuttingDown:
              summary: Instance shutting down
              value:
                type: https://docs.elunyo.app/errors/service_unavailable
                title: Service unavailable
                status: 503
                detail: The service is restarting. Try again shortly.
                code: service_unavailable
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    BadRequest:
      description: The request is not valid. Fix it before sending it again.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            validationFailed:
              summary: Invalid field
              value:
                type: https://docs.elunyo.app/errors/validation_failed
                title: Validation failed
                status: 400
                detail: The content field is required.
                code: validation_failed
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    Unauthenticated:
      description: There is no valid session. Sign in again.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            unauthenticated:
              summary: No session
              value:
                type: https://docs.elunyo.app/errors/unauthenticated
                title: Unauthenticated
                status: 401
                detail: Sign in to continue.
                code: unauthenticated
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    NotFound:
      description: The resource does not exist or belongs to another user.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            notFound:
              summary: Unknown conversation
              value:
                type: https://docs.elunyo.app/errors/not_found
                title: Not found
                status: 404
                detail: The conversation does not exist.
                code: not_found
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    RateLimited:
      description: Too many requests. Wait for the `Retry-After` seconds.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
        RateLimit:
          $ref: '#/components/headers/RateLimit'
        RateLimit-Policy:
          $ref: '#/components/headers/RateLimitPolicy'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            rateLimited:
              summary: Limit reached
              value:
                type: https://docs.elunyo.app/errors/rate_limited
                title: Too many requests
                status: 429
                detail: Too many requests. Try again later.
                code: rate_limited
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    Forbidden:
      description: |
        The session cannot do this. Requests that change state from the web app
        also get this answer without the `X-Requested-With: elunyo-web` header.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            forbidden:
              summary: Missing CSRF header
              value:
                type: https://docs.elunyo.app/errors/forbidden
                title: Forbidden
                status: 403
                detail: The X-Requested-With header is missing.
                code: forbidden
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    Conflict:
      description: The request conflicts with the current state.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            lastIdentity:
              summary: Only linked account
              value:
                type: https://docs.elunyo.app/errors/last_identity
                title: Last identity
                status: 409
                detail: The only linked account cannot be removed.
                code: last_identity
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
            generationInProgress:
              summary: Answer in progress
              value:
                type: https://docs.elunyo.app/errors/generation_in_progress
                title: Generation in progress
                status: 409
                detail: The conversation is still answering.
                code: generation_in_progress
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    PayloadTooLarge:
      description: The body is larger than this endpoint accepts.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          examples:
            payloadTooLarge:
              summary: Body too large
              value:
                type: https://docs.elunyo.app/errors/payload_too_large
                title: Payload too large
                status: 413
                detail: The request body is larger than 64 KB.
                code: payload_too_large
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    PaymentRequired:
      description: |
        There is no way to pay for this answer: the free messages of today are
        used up, or the balance does not cover the hold.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/PaymentRequiredProblem'
          examples:
            freeQuotaExhausted:
              summary: Free messages used up
              value:
                type: https://docs.elunyo.app/errors/free_quota_exhausted
                title: Free quota exhausted
                status: 402
                detail: The free messages of today are used up.
                code: free_quota_exhausted
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
                limit: 20
                resets_at: '2026-11-20T23:00:00Z'
            insufficientBalance:
              summary: Balance too low
              value:
                type: https://docs.elunyo.app/errors/insufficient_balance
                title: Insufficient balance
                status: 402
                detail: The balance does not cover the hold for this message.
                code: insufficient_balance
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
                needed:
                  amount_cents: 2400
                  currency: AOA
                balance:
                  amount_cents: 0
                  currency: AOA
    ChatUnavailable:
      description: |
        The model cannot answer now (`model_unavailable`, with `alternatives`), or
        the service is overloaded (`service_unavailable`, with `Retry-After`).
      headers:
        X-Request-ID:
          $ref: '#/components/headers/RequestId'
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ModelUnavailableProblem'
          examples:
            modelUnavailable:
              summary: Model unavailable
              value:
                type: https://docs.elunyo.app/errors/model_unavailable
                title: Model unavailable
                status: 503
                detail: The model is not available right now.
                code: model_unavailable
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
                alternatives:
                  - deepseek-v4.1-flash
            overloaded:
              summary: Too many streams on this instance
              value:
                type: https://docs.elunyo.app/errors/service_unavailable
                title: Service unavailable
                status: 503
                detail: Too many answers in progress. Try again shortly.
                code: service_unavailable
                request_id: 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
  headers:
    RequestId:
      description: |
        Request id. It is the value the client sent in `X-Request-ID` when that
        value has 1 to 64 letters, digits, `.`, `_` or `-`. Otherwise it is a UUIDv7
        generated by the server.
      schema:
        type: string
        examples:
          - 0193c4f8-7a52-7b1e-9d3a-5f2c8e6b4a10
    RetryAfter:
      description: Number of seconds to wait before retrying the request.
      schema:
        type: integer
        format: int32
        minimum: 0
        examples:
          - 5
    Location:
      description: Where the browser goes next.
      schema:
        type: string
        format: uri
        examples:
          - https://accounts.google.com/o/oauth2/v2/auth?client_id=example
    SetCookie:
      description: Cookies set or cleared by this answer. They are `HttpOnly` and `SameSite=Lax`, and `Secure` outside local development.
      schema:
        type: string
        examples:
          - sid=example; Path=/; HttpOnly; Secure; SameSite=Lax; Max-Age=2592000
    RateLimit:
      description: |
        Remaining quota of the limit that applies, in the format of the IETF
        draft "RateLimit header fields for HTTP", for example `"user";r=0;t=12`.
      schema:
        type: string
        examples:
          - '"user";r=0;t=12'
    RateLimitPolicy:
      description: Policy of the limit that applies, for example `"user";q=30;w=60` (30 requests per 60 seconds).
      schema:
        type: string
        examples:
          - '"user";q=30;w=60'
    CacheControl:
      description: How long clients and caches may reuse the answer.
      schema:
        type: string
        examples:
          - public, max-age=60
    ETag:
      description: Version of the answer. It changes with the `pricing_version`.
      schema:
        type: string
        examples:
          - '"pv_9f2c1a7e"'
  parameters:
    Provider:
      name: provider
      in: path
      required: true
      description: Social login provider.
      schema:
        $ref: '#/components/schemas/AuthProvider'
    Cursor:
      name: cursor
      in: query
      required: false
      description: Opaque cursor from `next_cursor` of the previous page. Leave out for the first page.
      schema:
        type: string
        maxLength: 200
    Limit:
      name: limit
      in: query
      required: false
      description: Items per page, from 1 to 100. Default 30.
      schema:
        type: integer
        format: int32
        minimum: 1
        maximum: 100
        default: 30
    ConversationId:
      name: conversation_id
      in: path
      required: true
      description: Conversation id.
      schema:
        type: string
        format: uuid
        examples:
          - 0193c4f8-8b10-7c2d-a1e4-2b9f0c7d6e55
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: |
        Key the client generates once per operation. Repeating the request with
        the same key has no second effect.
      schema:
        type: string
        minLength: 1
        maxLength: 64
    MessageId:
      name: message_id
      in: path
      required: true
      description: Message id.
      schema:
        type: string
        format: uuid
        examples:
          - 0193c4f9-1d2e-7a3b-8c4d-5e6f7a8b9c0d
    LastEventId:
      name: Last-Event-ID
      in: header
      required: false
      description: Id of the last event received. The stream continues after it. Leave out to start from the first event.
      schema:
        type: string
        maxLength: 20
    IdempotencyKeyRequired:
      name: Idempotency-Key
      in: header
      required: true
      description: |
        Key the client generates once per operation, such as a UUID. Repeating
        the request with the same key and the same body returns the first result
        and has no second effect. The same key with a different body answers 409
        `idempotency_conflict`.
      schema:
        type: string
        minLength: 1
        maxLength: 64
    PaymentId:
      name: payment_id
      in: path
      required: true
      description: Payment id.
      schema:
        type: string
        format: uuid
        examples:
          - 0193c5a0-4b1c-7d2e-9f30-1a2b3c4d5e6f
    ImageId:
      name: image_id
      in: path
      required: true
      description: Image id.
      schema:
        type: string
        format: uuid
        examples:
          - 0193c6b2-5a10-7c3d-8e4f-1a2b3c4d5e6f
