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

# Stream a Codex subscription response

> Forward the official Codex client's native request to the fixed OpenAI Codex backend using its ChatGPT token. The separate personal Aixy key selects the authorized project and user. Supports HTTP SSE with supports_websockets=false in Codex configuration. Native history, tool identifiers, encrypted reasoning and streaming events are preserved. Activity records billing_channel=subscription, reported usage and no API cost. ChatGPT limits and credits still apply. This route provides no cross-provider translation, fallback or subscription pooling.



## OpenAPI

````yaml /openapi.json post /backend-api/codex/responses
openapi: 3.1.0
info:
  title: Aixy Inference API
  version: 0.1.0
  description: >-
    Route requests to configured AI providers through OpenAI- and
    Anthropic-compatible APIs. Aixy applies project access, model policies,
    guardrails, routing, budgets, and usage attribution before forwarding
    inference traffic. Create connections, API keys and policies in the Aixy
    dashboard. The management API is a dashboard service and is not a public
    integration contract. Native provider features depend on the selected model
    and connection; translated requests support the documented conversation and
    function-tool subset. Unsupported combinations return explicit errors.
    Examples use illustrative model IDs; select an ID available to your project.
servers:
  - url: https://api.aixy-gateway.com
    description: Aixy production gateway
security: []
tags:
  - name: OpenAI
    description: OpenAI-compatible conversations, function tools and incremental streams.
  - name: Anthropic
    description: Anthropic-compatible messages and provider-native input token counting.
  - name: Decisions
    description: Typed, non-streaming classification and scoring inference.
  - name: Models
    description: Discover the models available to your project API key.
  - name: Codex
    description: Use the official Codex client with each user's ChatGPT subscription.
paths:
  /backend-api/codex/responses:
    post:
      tags:
        - Codex
      summary: Stream a Codex subscription response
      description: >-
        Forward the official Codex client's native request to the fixed OpenAI
        Codex backend using its ChatGPT token. The separate personal Aixy key
        selects the authorized project and user. Supports HTTP SSE with
        supports_websockets=false in Codex configuration. Native history, tool
        identifiers, encrypted reasoning and streaming events are preserved.
        Activity records billing_channel=subscription, reported usage and no API
        cost. ChatGPT limits and credits still apply. This route provides no
        cross-provider translation, fallback or subscription pooling.
      operationId: create_codex_subscription_response
      parameters:
        - $ref: '#/components/parameters/XRequestId'
        - $ref: '#/components/parameters/XAixySessionId'
        - name: ChatGPT-Account-ID
          in: header
          required: false
          schema:
            type: string
          description: >-
            Account/workspace selected by Codex; preserved for OpenAI
            validation. It does not select or authorize an Aixy tenant.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CodexResponsesRequest'
            example:
              model: native-model-id
              input:
                - role: user
                  content:
                    - type: input_text
                      text: Hello
              stream: true
              store: false
      responses:
        '200':
          description: >-
            Incremental native SSE. A successful stream ends with
            response.completed; errors can occur after headers or text arrive.
          headers:
            x-request-id:
              description: >-
                Aixy request identifier for correlation with Activity and
                support.
              schema:
                type: string
              example: req_example_01
            openai-model:
              schema:
                type: string
              description: Effective upstream model, when reported.
            X-Models-Etag:
              schema:
                type: string
              description: Catalog revision observed by Codex.
            x-codex-turn-state:
              schema:
                type: string
              description: Opaque routing state for the same turn.
            x-codex-primary-used-percent:
              schema:
                type: string
              description: Used share of the provider's primary quota window.
            x-codex-secondary-used-percent:
              schema:
                type: string
              description: Used share of the provider's secondary quota window.
          content:
            text/event-stream:
              schema:
                type: string
              example: >+
                event: response.created

                data:
                {"type":"response.created","response":{"id":"resp_example"}}


                event: response.output_text.delta

                data: {"type":"response.output_text.delta","delta":"Hello"}


                event: response.completed

                data:
                {"type":"response.completed","response":{"id":"resp_example","usage":{"input_tokens":10,"output_tokens":1,"total_tokens":11}}}

        '400':
          $ref: '#/components/responses/GatewayError'
        '401':
          $ref: '#/components/responses/GatewayError'
        '403':
          $ref: '#/components/responses/GatewayError'
        '404':
          $ref: '#/components/responses/GatewayError'
        '408':
          $ref: '#/components/responses/GatewayError'
        '413':
          $ref: '#/components/responses/GatewayError'
        '429':
          $ref: '#/components/responses/GatewayError'
        '502':
          $ref: '#/components/responses/GatewayError'
        '503':
          $ref: '#/components/responses/GatewayError'
        '504':
          $ref: '#/components/responses/GatewayError'
        default:
          $ref: '#/components/responses/NativeProviderError'
      security:
        - CodexGatewayKey: []
          CodexChatGPTToken: []
components:
  parameters:
    XRequestId:
      name: X-Request-ID
      in: header
      required: false
      description: Optional caller-generated request identifier for end-to-end tracing.
      schema:
        type: string
        maxLength: 255
    XAixySessionId:
      name: X-Aixy-Session-ID
      in: header
      required: false
      description: >-
        Optional opaque conversation identifier recorded in Activity metadata.
        Reuse it for every call in a conversation. Sessions are isolated by
        organization, project, user and API key. Use no personal data or
        secrets. Invalid values are ignored. The header is not forwarded, grants
        no permissions and does not change routing affinity.
      schema:
        type: string
        minLength: 1
        maxLength: 128
        pattern: ^[A-Za-z0-9._:-]+$
        example: conversation-82
  schemas:
    CodexResponsesRequest:
      type: object
      required:
        - model
        - input
        - stream
        - store
      properties:
        model:
          type: string
          description: Native Codex model slug, without an Aixy provider prefix.
        input:
          type: array
          items:
            type: object
            additionalProperties: true
          description: Native conversation history, tool items and opaque reasoning state.
        stream:
          type: boolean
          const: true
        store:
          type: boolean
          const: false
      additionalProperties: true
    InferenceErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
          properties:
            message:
              type: string
            code:
              type:
                - string
                - 'null'
            type:
              type:
                - string
                - 'null'
            param:
              type:
                - string
                - integer
                - 'null'
            details:
              type:
                - object
                - 'null'
              additionalProperties: true
          additionalProperties: true
        type:
          type: string
        request_id:
          type: string
      additionalProperties: true
  responses:
    GatewayError:
      description: >-
        The gateway or upstream provider rejected the request. Gateway codes
        identify invalid_request or unsupported_feature (400),
        invalid_gateway_api_key (401), access or policy denials (403),
        unavailable models (404), request deadlines (408/504), body limits
        (413), hard-budget admission failures (424), and upstream or gateway
        availability failures (502/503). Native provider error details may
        differ.
      headers:
        x-request-id:
          description: Aixy request identifier for correlation with Activity and support.
          schema:
            type: string
          example: req_example_01
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/InferenceErrorResponse'
          example:
            error:
              code: invalid_gateway_api_key
              message: Gateway API key is invalid or revoked
    NativeProviderError:
      description: >-
        A native provider may return another error status and its original
        payload. After streaming starts, failures can arrive inside the SSE
        stream instead of changing the HTTP status. Handle both HTTP errors and
        protocol error events.
      headers:
        x-request-id:
          description: Aixy request identifier for correlation with Activity and support.
          schema:
            type: string
          example: req_example_01
      content:
        application/json:
          schema:
            type: object
            additionalProperties: true
  securitySchemes:
    CodexGatewayKey:
      type: apiKey
      in: header
      name: X-Gateway-Key
      description: >-
        The caller's personal, project-scoped Aixy key. Aixy validates and
        removes this header before forwarding. It does not replace the ChatGPT
        token.
    CodexChatGPTToken:
      type: http
      scheme: bearer
      description: >-
        The user's ChatGPT access token supplied by the official Codex client.
        Forwarded only to the fixed Codex backend; never stored as a connection.

````

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