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

# Create a response (OpenAI Responses protocol)

> Route an OpenAI Responses request. Uses `input` and `instructions`; returns an
`output` array. Additional Responses fields pass through.




## OpenAPI

````yaml /api-reference/context-router/context-router.oas.yaml post /responses
openapi: 3.1.0
info:
  title: Context Router API
  version: 1.0.0
  summary: >-
    OpenAI-compatible chat endpoints with routing, response caching and per-call
    templating.
  description: >
    Routes OpenAI-compatible requests to a configured model and returns the
    standard OpenAI

    response. Two endpoints share the same auth, routing, caching and
    templating:

      * `POST /chat/completions` - Chat Completions protocol. Recommended.
      * `POST /responses` - Responses protocol.

    SLNG request extensions: `template_variables`, `slng_config`,
    `slng_agent_id`,

    `slng_session_id`, `slng_analytics`, `slng_pure_proxy`. Response headers:

    `x-slng-request-id`, `x-slng-response-source`, `x-slng-model`.
servers:
  - url: https://{region}.context-router.slng.ai/v1
    description: Regional base URL. Pick the region closest to your callers.
    variables:
      region:
        default: india
        enum:
          - india
          - us
          - indonesia
        description: Deployment region. Other regions may exist.
security:
  - SlngApiKey: []
tags:
  - name: Chat
    description: OpenAI Chat Completions surface.
  - name: Responses
    description: OpenAI Responses-compatible endpoint.
paths:
  /responses:
    post:
      tags:
        - Responses
      summary: Create a response (OpenAI Responses protocol)
      description: >
        Route an OpenAI Responses request. Uses `input` and `instructions`;
        returns an

        `output` array. Additional Responses fields pass through.
      operationId: createResponse
      parameters:
        - $ref: '#/components/parameters/XSlngAgentId'
        - $ref: '#/components/parameters/XSlngSessionId'
        - $ref: '#/components/parameters/XSlngRequestId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ResponsesRequest'
      responses:
        '200':
          description: A Responses-protocol envelope.
          headers:
            x-slng-request-id:
              $ref: '#/components/headers/XSlngRequestIdResponse'
            x-slng-response-source:
              $ref: '#/components/headers/XSlngResponseSource'
            x-slng-model:
              $ref: '#/components/headers/XSlngModel'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResponsesResponse'
        '400':
          description: Bad request. Same error codes as `/chat/completions`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Unprocessable request. Same error codes as `/chat/completions`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  parameters:
    XSlngAgentId:
      name: X-Slng-Agent-Id
      in: header
      required: false
      description: >
        Stable agent ID. Scopes the cache — change it when the system prompt
        changes. Required

        unless sent as `slng_agent_id` (body wins). Max 256 chars; no
        whitespace, commas, pipes

        or braces.
      schema:
        $ref: '#/components/schemas/SlngId'
      example: clinic-scheduler-v1
    XSlngSessionId:
      name: X-Slng-Session-Id
      in: header
      required: false
      description: |
        ID for a single call, constant across its turns. Required unless sent as
        `slng_session_id` (body wins). Same character rules as the agent ID.
      schema:
        $ref: '#/components/schemas/SlngId'
      example: call-8f2c1a4e-9b07-4d3a-a1e2-7c5f0d6b2a11
    XSlngRequestId:
      name: X-Slng-Request-Id
      in: header
      required: false
      description: >
        Optional correlation ID, echoed back in `x-slng-request-id`.
        `X-Request-Id` is also

        accepted.
      schema:
        type: string
  schemas:
    ResponsesRequest:
      type: object
      additionalProperties: true
      description: >
        OpenAI Responses body (`input` and `instructions`), plus the same SLNG
        extensions as Chat Completions.
      properties:
        model:
          type: string
          default: slng/auto
        input:
          description: Responses-protocol input.
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
        instructions:
          type: string
        stream:
          type: boolean
        template_variables:
          $ref: '#/components/schemas/TemplateVariables'
        slng_config:
          $ref: '#/components/schemas/SlngConfig'
        slng_agent_id:
          $ref: '#/components/schemas/SlngId'
        slng_session_id:
          $ref: '#/components/schemas/SlngId'
        slng_analytics:
          type: boolean
          default: false
        slng_pure_proxy:
          type: boolean
          default: false
    ResponsesResponse:
      type: object
      additionalProperties: true
      description: OpenAI Responses-compatible `output` envelope.
      properties:
        id:
          type: string
        object:
          type: string
        model:
          type: string
        output:
          type: array
          items:
            type: object
            additionalProperties: true
        usage:
          type: object
          additionalProperties: true
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
              example: invalid_request_error
            param:
              type:
                - string
                - 'null'
            code:
              type: string
              enum:
                - missing_client_id
                - invalid_client_id
                - missing_template_variables
                - invalid_slng_config
              description: >
                Error code. `slng_config` failures other than a non-object body
                return a 400 with a message beginning `invalid slng_config:`.
    SlngId:
      type: string
      maxLength: 256
      pattern: ^[^\s,|{}]+$
      description: |
        Opaque ID. Max 256 characters; no whitespace, commas, pipes or braces.
    TemplateVariables:
      type: object
      maxProperties: 64
      description: >
        SLNG extension. `{name: value}` map substituted into `{{name}}`
        placeholders in the

        **system message only**. Names are letters, digits and underscore.


        Limits (over any returns 422): 64 variables, 64-char names, 4000-char
        values. A

        `{{name}}` with no value returns 422 (`missing_template_variables`);
        unused variables

        are ignored.


        Use for personalization that is spoken or echoed. Values that steer the
        answer

        (language, plan, region) belong in the prompt — steering here can make
        the cache serve

        another caller's answer.
      propertyNames:
        pattern: ^[A-Za-z0-9_]{1,64}$
      additionalProperties:
        type: string
        maxLength: 4000
      example:
        caller_name: Rajesh
        city: Mumbai
    SlngConfig:
      type: object
      required:
        - tiers
      additionalProperties: false
      description: >
        SLNG extension. Model endpoints and provider keys sent inline, replacing
        your saved

        configuration for that request. Treat as a credential (HTTPS, keep out
        of logs); under

        256 KB serialized. Invalid config returns 400 (`invalid slng_config:`);
        a non-object

        returns 422 (`invalid_slng_config`).
      properties:
        tiers:
          type: object
          description: >
            Up to three tiers (`"1"`, `"2"`, `"3"`) tried in order. Within a
            tier, traffic

            splits by `weight` (summing to 100). A failed model (5xx, timeout,
            429) retries

            once against the next option.
          propertyNames:
            enum:
              - '1'
              - '2'
              - '3'
          additionalProperties:
            type: array
            minItems: 1
            items:
              $ref: '#/components/schemas/SlngConfigEntry'
    SlngConfigEntry:
      type: object
      required:
        - model
        - weight
        - endpoint
      additionalProperties: false
      properties:
        model:
          type: string
          description: >
            Label for this entry. Pass it as the request `model` to target it
            directly.
        weight:
          type: integer
          minimum: 1
          maximum: 100
          description: Share of the tier's traffic; weights in a tier sum to 100.
        endpoint:
          $ref: '#/components/schemas/SlngEndpoint'
    SlngEndpoint:
      type: object
      additionalProperties: false
      description: >
        Where the model is served, with its credentials. Required fields depend
        on `provider`;

        fields for another provider are rejected.
      properties:
        provider:
          type: string
          default: openai-compat
          enum:
            - openai-compat
            - openai-responses
            - azure
            - vertex
            - bedrock
          description: >
            `openai-compat` (default) for any OpenAI Chat Completions service
            (OpenAI, Groq,

            vLLM, and so on). `openai-responses` calls the upstream Responses
            API instead — for

            models that only work that way, typically reasoning models that
            refuse tools.
        url:
          type: string
          format: uri
          description: >
            Required for `openai-compat`, `openai-responses` and `azure`. For
            `azure`, the

            resource **root**
            (`https://my-resource.cognitiveservices.azure.com/`), not the

            deployment URL.
        api_key:
          type: string
          description: >
            Required for `openai-compat`, `openai-responses` and `azure`. Your
            provider key, not your SLNG key.
        auth_header:
          type: string
          description: >
            Optional (`openai-compat`). Custom key header, for example
            `x-goog-api-key` for Gemini.
        model_id:
          type: string
          description: >
            Model name sent to the provider when it differs from the `model`
            label. Required for `bedrock`.
        azure_deployment:
          type: string
          description: 'Required for `provider: azure`. The Azure deployment name.'
        api_version:
          type: string
          description: 'Required for `provider: azure`, for example `2024-12-01-preview`.'
        vertex_credentials:
          type: object
          additionalProperties: true
          description: >
            Required for `provider: vertex`. GCP service-account key as a JSON
            object.
        vertex_location:
          type: string
          description: 'Required for `provider: vertex`. The Vertex AI location.'
        vertex_project:
          type: string
          description: >
            Optional for `provider: vertex`. Defaults to the service-account
            key's project.
        aws_access_key_id:
          type: string
          description: 'Required for `provider: bedrock`.'
        aws_secret_access_key:
          type: string
          description: 'Required for `provider: bedrock`.'
        aws_region:
          type: string
          description: 'Required for `provider: bedrock`.'
        aws_session_token:
          type: string
          description: 'Optional for `provider: bedrock`, for temporary credentials.'
      examples:
        - url: https://api.openai.com/v1
          api_key: sk-...
        - provider: azure
          url: https://my-resource.cognitiveservices.azure.com/
          api_key: ...
          azure_deployment: gpt-4o-deploy
          api_version: 2024-12-01-preview
        - provider: bedrock
          aws_access_key_id: AKIA...
          aws_secret_access_key: ...
          aws_region: ap-south-1
          model_id: anthropic.claude-3-5-sonnet-20241022-v2:0
  headers:
    XSlngRequestIdResponse:
      description: >
        The router's ID for this request, on every response. Quote it in support
        requests.
      schema:
        type: string
    XSlngResponseSource:
      description: >
        Answer source: `llm` (live model) or `cache`. `router` and `analytics`
        appear only

        with those features.
      schema:
        type: string
        enum:
          - llm
          - cache
          - router
          - analytics
    XSlngModel:
      description: >
        The model that produced the answer, after any failover. Live answers
        only.
      schema:
        type: string
  securitySchemes:
    SlngApiKey:
      type: http
      scheme: bearer
      description: >
        Send your SLNG API key as a Bearer token (an OpenAI SDK's `api_key`
        option). Provider

        credentials in `slng_config` authenticate to those providers.

````