> ## Documentation Index
> Fetch the complete documentation index at: https://agency-swarm.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Stream API v2 completion

> Starts an SSE agent run. When allowances are enabled, consumerId and usageRequestId are required. An in-progress response may finish above the limit; the next request is rejected. Every request must use the integration owner's API key. Errors with X-Agent-Run-Admitted: false were rejected before reserving a run. If that header is absent after an interruption, check chat status using the same usageRequestId before retrying. A failed response stays in chat history. Its attachments are not sent again in later turns; attach them again to retry. Other messages and their successful attachments remain available.



## OpenAPI

````yaml /openapi.json post /get_completion_v2
openapi: 3.0.3
info:
  title: Agencii Platform API
  version: 1.0.0
  description: >-
    Reference documentation for the Agencii Platform API. Provides endpoints
    allowing you to run your agents on custom backends or on other unsupported
    channels. ⚡ Live Postman Example:
    https://www.postman.com/vrsen-ai/agencii-api/overview
servers:
  - url: https://agency-swarm-app-japboyzddq-uc.a.run.app
    description: Production server
security:
  - BearerAuth: []
paths:
  /get_completion_v2:
    post:
      summary: Stream API v2 completion
      description: >-
        Starts an SSE agent run. When allowances are enabled, consumerId and
        usageRequestId are required. An in-progress response may finish above
        the limit; the next request is rejected. Every request must use the
        integration owner's API key. Errors with X-Agent-Run-Admitted: false
        were rejected before reserving a run. If that header is absent after an
        interruption, check chat status using the same usageRequestId before
        retrying. A failed response stays in chat history. Its attachments are
        not sent again in later turns; attach them again to retry. Other
        messages and their successful attachments remain available.
      operationId: getCompletionV2
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GetCompletionV2Request'
      responses:
        '200':
          description: >-
            Server-sent events by default, or plain text when Text Only Mode is
            enabled for the integration.
          content:
            text/event-stream:
              schema:
                type: string
            text/plain:
              schema:
                type: string
        '400':
          description: Invalid request or missing allowance attribution.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
          headers:
            X-Agent-Run-Admitted:
              description: >-
                false means no run was reserved. An absent header does not prove
                rejection.
              schema:
                type: string
                enum:
                  - 'false'
        '401':
          description: Missing or invalid platform API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
          headers:
            X-Agent-Run-Admitted:
              description: >-
                false means no run was reserved. An absent header does not prove
                rejection.
              schema:
                type: string
                enum:
                  - 'false'
        '403':
          description: The API key does not own this integration.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
          headers:
            X-Agent-Run-Admitted:
              description: >-
                false means no run was reserved. An absent header does not prove
                rejection.
              schema:
                type: string
                enum:
                  - 'false'
        '404':
          description: >-
            Integration or member not found. Register the member before starting
            a completion.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
          headers:
            X-Agent-Run-Admitted:
              description: >-
                false means no run was reserved. An absent header does not prove
                rejection.
              schema:
                type: string
                enum:
                  - 'false'
        '409':
          description: >-
            The previous run is still active. Wait or cancel that exact run
            before starting another.
          headers:
            X-Agent-Run-Admitted:
              description: >-
                false means no run was reserved. An absent header does not prove
                rejection.
              schema:
                type: string
                enum:
                  - 'false'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
        '429':
          description: Consumer is inactive or has exhausted the current allowance.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
          headers:
            X-Agent-Run-Admitted:
              description: >-
                false means no run was reserved. An absent header does not prove
                rejection.
              schema:
                type: string
                enum:
                  - 'false'
      servers:
        - url: https://api-integration-v2-qd6wo466iq-uc.a.run.app
          description: Staging API v2 server
components:
  schemas:
    GetCompletionV2Request:
      type: object
      required:
        - apiIntegrationId
        - message
      properties:
        apiIntegrationId:
          type: string
        message:
          type: string
        agent:
          type: string
          description: Agency entry point. The integration default is used when omitted.
        chatId:
          type: string
          nullable: true
        aliasChatId:
          type: string
          nullable: true
        attachments:
          type: array
          maxItems: 5
          items:
            $ref: '#/components/schemas/ApiV2Attachment'
        sandboxFiles:
          type: array
          maxItems: 5
          description: >-
            Files already uploaded into this integration's persistent agency
            mount. The agent can read these paths with sandbox tools; send
            images in attachments as well when the model should see them.
          items:
            type: object
            required:
              - name
              - path
            properties:
              name:
                type: string
                description: >-
                  Uploaded filename. Must match the final path segment and
                  contain no control characters.
              path:
                type: string
                description: Canonical /app/mnt/ path returned by create_agency_upload.
        user_context:
          oneOf:
            - type: object
              additionalProperties: true
            - type: string
          nullable: true
        consumerId:
          type: string
          description: Required when member allowances are enabled.
        usageRequestId:
          type: string
          description: >-
            Unique ID for this request, included in chat status and usage
            records. Required when allowances are enabled. Match it when
            recovering an interrupted request.
        attachmentUrlRefreshes:
          type: object
          additionalProperties:
            type: string
            format: uri
          description: >-
            Map each expired earlier attachment URL without its query string to
            a fresh HTTPS URL with the same host and path. Include all earlier
            conversation files that need refreshing.
    ApiErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
        code:
          type: string
          nullable: true
          example: consumer_allowance_exhausted
    ApiV2Attachment:
      oneOf:
        - $ref: '#/components/schemas/ApiV2FileAttachment'
        - $ref: '#/components/schemas/ApiV2ImageAttachment'
      discriminator:
        propertyName: type
        mapping:
          input_file:
            $ref: '#/components/schemas/ApiV2FileAttachment'
          input_image:
            $ref: '#/components/schemas/ApiV2ImageAttachment'
    ApiV2FileAttachment:
      type: object
      additionalProperties: false
      required:
        - type
        - file_url
      properties:
        type:
          type: string
          enum:
            - input_file
        file_url:
          type: string
          format: uri
          description: A publicly accessible HTTPS URL for the file.
        filename:
          type: string
          description: Optional file name without a directory path.
    ApiV2ImageAttachment:
      type: object
      additionalProperties: false
      required:
        - type
        - image_url
      properties:
        type:
          type: string
          enum:
            - input_image
        image_url:
          type: string
          minLength: 1
          description: A publicly accessible HTTPS image URL or an inline image data URL.
        detail:
          type: string
          enum:
            - auto
            - low
            - high
          default: auto
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Platform token required for authentication. Find or create one inside
        Profile Icon > API Keys. Example: Bearer sk-agencii-...

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.