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

# OpenAI-compatible chat-completions endpoint routed through an LLM gateway

> **Security Requirements**

| Auth Types | Entities | Permissions | Required Roles |
|------------|----------|-------------|----------------|
| AGENT, USER | LLM_GATEWAY | READ | LLM_GATEWAY:READ |

Tenant is derived from the authenticated principal — callers do not pass it in the URL. The principal (user or agent) must hold an active subscription on the target gateway; RBAC alone is not sufficient. Callers SHOULD propagate the swarmd correlation id via the X-Correlation-Id header so the LLM call is stitched to the inbound agent task in audit traces. If the header is absent the gateway generates one.



## OpenAPI

````yaml /openapi/swarmd.json post /relay/llm/v1/{gatewayId}/chat/completions
openapi: 3.1.0
info:
  title: Relay
  version: v0
servers:
  - url: https://api.dev.swarmd.ai
    description: Development
security: []
tags:
  - name: Policy Groups
    x-displayName: Policy Groups
  - name: Policy Bindings
    x-displayName: Policy Bindings
  - name: Evaluation Packs
    x-displayName: Evaluation Packs
  - name: Webhooks
    x-displayName: Webhooks
  - name: MCP JSON-RPC
    x-displayName: MCP JSON-RPC
  - name: Conversations
    x-displayName: Conversations
  - name: Human JSON-RPC
    x-displayName: Human JSON-RPC
  - name: Channel JSON-RPC
    x-displayName: Channel JSON-RPC
  - name: HITL Approvals
    x-displayName: HITL Approvals
  - name: Agent JSON-RPC
    x-displayName: Agent JSON-RPC
  - name: Tasks
    x-displayName: Tasks
  - name: Push Notifications
    x-displayName: Push Notifications
  - name: Messaging
    x-displayName: Messaging
  - name: LLM Runtime
    x-displayName: LLM Runtime
  - name: Agent Discovery
    x-displayName: Agent Discovery
  - name: MCP Servers
    x-displayName: MCP Servers
  - name: LLM Gateways
    x-displayName: LLM Gateways
  - name: Agents
    x-displayName: Agents
  - name: User Subscriptions
    x-displayName: User Subscriptions
  - name: LLM Providers
    x-displayName: LLM Providers
  - name: LLM Gateway Subscriptions
    x-displayName: LLM Gateway Subscriptions
  - name: Kill Switches
    x-displayName: Kill Switches
  - name: Channels
    x-displayName: Channels
  - name: Channel Subscriptions
    x-displayName: Channel Subscriptions
  - name: Agent Subscriptions
    x-displayName: Agent Subscriptions
  - name: Marketplace
    x-displayName: Marketplace
  - name: Identity Providers
    x-displayName: Identity Providers
  - name: Groups
    x-displayName: Groups
  - name: Authentication
    x-displayName: Authentication
  - name: Users
    x-displayName: Users
  - name: Tenants
    x-displayName: Tenants
  - name: mcp-consent-controller
    x-displayName: mcp-consent-controller
  - name: Audit Monitors
    x-displayName: Audit Monitors
  - name: Audit Integrity
    x-displayName: Audit Integrity
  - name: Audit Events
    x-displayName: Audit Events
  - name: Audit Traces
    x-displayName: Audit Traces
  - name: audit-rest-controller
    x-displayName: audit-rest-controller
  - name: Audit Dashboard
    x-displayName: Audit Dashboard
  - name: A2A Payments
    x-displayName: A2A Payments
paths:
  /relay/llm/v1/{gatewayId}/chat/completions:
    post:
      tags:
        - LLM Runtime
      summary: >-
        OpenAI-compatible chat-completions endpoint routed through an LLM
        gateway
      description: >-
        **Security Requirements**


        | Auth Types | Entities | Permissions | Required Roles |

        |------------|----------|-------------|----------------|

        | AGENT, USER | LLM_GATEWAY | READ | LLM_GATEWAY:READ |


        Tenant is derived from the authenticated principal — callers do not pass
        it in the URL. The principal (user or agent) must hold an active
        subscription on the target gateway; RBAC alone is not sufficient.
        Callers SHOULD propagate the swarmd correlation id via the
        X-Correlation-Id header so the LLM call is stitched to the inbound agent
        task in audit traces. If the header is absent the gateway generates one.
      operationId: chatCompletions
      parameters:
        - name: gatewayId
          in: path
          required: true
          schema:
            type: string
            format: uuid
        - name: X-Correlation-Id
          in: header
          description: >-
            Swarmd correlation id stitched into audit events. The
            MdcLoggingFilter extracts it from this header (or generates a UUID
            when absent) and the chain propagates it onto every emitted audit
            event so multi-agent + multi-LLM workloads are joined by a single
            id.
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Relay_ChatCompletionRequest'
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
      security:
        - Relay_bearerAuth: []
components:
  schemas:
    Relay_ChatCompletionRequest:
      type: object
      properties:
        model:
          type: string
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Relay_ChatCompletionMessage'
          minItems: 1
        temperature:
          type: number
          format: double
        max_tokens:
          type: integer
          format: int32
        top_p:
          type: number
          format: double
        stream:
          type: boolean
        metadata:
          type: object
          additionalProperties:
            type: string
        tools:
          type: array
          items:
            $ref: '#/components/schemas/Relay_ChatCompletionTool'
        tool_choice:
          path: /audit/v1/agents/{agentId}/metrics
        response_format:
          path: /audit/v1/agents/{agentId}/metrics
        parallel_tool_calls:
          type: boolean
        seed:
          type: integer
          format: int32
      required:
        - messages
    Relay_ChatCompletionMessage:
      type: object
      properties:
        role:
          type: string
        content:
          path: /audit/v1/agents/{agentId}/metrics
        name:
          type: string
        tool_calls:
          type: array
          items:
            $ref: '#/components/schemas/Relay_ChatCompletionToolCall'
        tool_call_id:
          type: string
        refusal:
          type: string
    Relay_ChatCompletionTool:
      type: object
      properties:
        type:
          type: string
        function:
          $ref: '#/components/schemas/Relay_ChatCompletionFunctionDefinition'
    Relay_ChatCompletionToolCall:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
        function:
          $ref: '#/components/schemas/Relay_ChatCompletionToolCallFunction'
    Relay_ChatCompletionFunctionDefinition:
      type: object
      properties:
        name:
          type: string
        description:
          type: string
        parameters:
          path: /audit/v1/agents/{agentId}/metrics
    Relay_ChatCompletionToolCallFunction:
      type: object
      properties:
        name:
          type: string
        arguments:
          type: string
  securitySchemes:
    Relay_bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT token (USER, AGENT, or SERVICE auth)

````