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

# Create Chat Completion

> OpenAI-compatible chat completions endpoint backed by Eachlabs LLM Router. Use
`Authorization: Bearer <API_KEY>` and point an OpenAI-compatible client at
`https://api.eachlabs.ai/v1`.

This endpoint uses the OpenAI-compatible error envelope rather than the REST
error body described in the global contract notes.




## OpenAPI

````yaml /openapi_specs/models.json post /v1/chat/completions
openapi: 3.0.3
info:
  title: each::labs Official API v1
  description: >
    Official each::labs API V1.

    This API provides access to our comprehensive AI model catalog and other
    resources.


    ## Public contract notes


    - Public API routes handled by request logging include `X-Request-Id` for
      support and log correlation. Clients may send `X-Request-Id`; otherwise
      api-service generates one. Root, health, and metrics endpoints are excluded.
    - REST error bodies keep the backward-compatible JSON shape used by existing
      clients. Most errors include at least `error`; some shared error paths also
      include `status` and `details`. Use the HTTP status code as the primary
      programmatic signal unless an endpoint documents a richer envelope.
    - Rate-limit and retry headers are endpoint-dependent. If a response
    includes
      `Retry-After`, honor it before retrying; otherwise use bounded exponential
      backoff for retryable 429/5xx responses.
    - api-service exposes single workflow trigger through
      `/v1/workflows/trigger/{workflowID}/{versionID}`. Bulk workflow trigger is
      not routed through api-service; use the workflows-engine public API directly
      where bulk trigger is required.
  version: 1.0.0
  contact:
    name: API Support
    email: support@eachlabs.ai
  x-logo:
    url: ./logo-white.svg
    altText: each::labs
servers:
  - url: https://api.eachlabs.ai
    description: Production server
security: []
tags:
  - name: AI Models
    description: Endpoints for listing and retrieving AI models and other resources.
  - name: AI Models Prediction
    description: Endpoints for managing model predictions
  - name: Uploads
    description: Endpoints for uploading files that can be used as model inputs.
  - name: Executions
    description: Endpoints for listing execution history.
  - name: Workflows
    description: Endpoints for triggering workflow executions through api-service.
  - name: OpenAI Compatibility
    description: OpenAI-compatible endpoints for LLM Router requests.
  - name: Webhooks
    description: >
      Endpoints for retrieving webhook information and delivery history.


      **Note:** Currently, webhooks are only supported for Workflows V2. We are
      actively expanding webhook support to other services and will update this
      documentation as new integrations become available.
paths:
  /v1/chat/completions:
    post:
      tags:
        - OpenAI Compatibility
      summary: Create Chat Completion
      description: >
        OpenAI-compatible chat completions endpoint backed by Eachlabs LLM
        Router. Use

        `Authorization: Bearer <API_KEY>` and point an OpenAI-compatible client
        at

        `https://api.eachlabs.ai/v1`.


        This endpoint uses the OpenAI-compatible error envelope rather than the
        REST

        error body described in the global contract notes.
      operationId: createChatCompletion
      parameters:
        - name: X-Eachlabs-Webhook-Url
          in: header
          required: false
          schema:
            type: string
            format: uri
          description: Optional webhook URL for asynchronous result delivery.
          example: https://your-app.com/webhook
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            example:
              model: openai/gpt-4o-mini
              messages:
                - role: user
                  content: Write a one sentence caption.
      responses:
        '200':
          description: >-
            OpenAI-compatible chat completion. Requests with `stream: true`
            return Server-Sent Events.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                type: string
                description: |
                  Server-Sent Events stream for requests with `stream: true`.
                  Events use OpenAI-compatible `chat.completion.chunk` payloads
                  and the stream terminates with `data: [DONE]`.
              example: >
                data:
                {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"A
                cinematic"},"finish_reason":null}]}


                data: [DONE]
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIErrorResponse'
        '401':
          description: Authentication failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIErrorResponse'
        '402':
          description: Insufficient balance
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIErrorResponse'
      security:
        - BearerAuth: []
components:
  schemas:
    ChatCompletionRequest:
      type: object
      description: OpenAI-compatible chat completions request body
      required:
        - model
        - messages
      additionalProperties: true
      properties:
        model:
          type: string
          description: LLM model identifier
          example: openai/gpt-4o-mini
        messages:
          type: array
          items:
            type: object
            additionalProperties: true
          description: OpenAI-compatible chat messages
          example:
            - role: user
              content: Write a one sentence caption.
        stream:
          type: boolean
          description: >-
            Set to `true` to receive OpenAI-compatible SSE chunks
            (`text/event-stream`) instead of a buffered JSON response.
          example: false
        stream_options:
          type: object
          nullable: true
          additionalProperties: true
          description: >-
            Optional OpenAI-compatible streaming options. When `include_usage`
            is true, the stream may include a final usage chunk before `[DONE]`.
          properties:
            include_usage:
              type: boolean
              description: >-
                Include token usage in the streamed response when provider usage
                data is available.
              example: true
    ChatCompletionResponse:
      type: object
      description: OpenAI-compatible chat completions response
      properties:
        id:
          type: string
          example: chatcmpl-abc123
        object:
          type: string
          example: chat.completion
        created:
          type: integer
          format: int64
          example: 1773651600
        model:
          type: string
          example: eachlabs-llm-router
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
                example: 0
              message:
                type: object
                properties:
                  role:
                    type: string
                    example: assistant
                  content:
                    type: string
                    example: A cinematic sunset over the ocean.
              finish_reason:
                type: string
                example: stop
        usage:
          type: object
          nullable: true
          properties:
            prompt_tokens:
              type: integer
              example: 12
            completion_tokens:
              type: integer
              example: 8
            total_tokens:
              type: integer
              example: 20
    OpenAIErrorResponse:
      type: object
      description: OpenAI-compatible error envelope used only by `/v1/chat/completions`.
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Invalid API key
            type:
              type: string
              example: authentication_error
            param:
              type: string
              example: model
            code:
              type: string
              example: invalid_api_key
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        API key passed as an Authorization Bearer token for OpenAI-compatible
        endpoints

````