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

# Handle an OpenAI Chat Completions-compatible request, streaming or returning the assembled response



## OpenAPI

````yaml /openapi/v1.json post /chat/completions
openapi: 3.1.0
info:
  title: HASP AI API
  version: '2026-07-12'
  description: >-
    The HASP Public AI API is the regulated-AI substrate for healthcare and
    other

    regulated industries — identity, policy, audit, compliance, and PHI handling

    for AI inference, exposed via two surfaces:


    - **Native (`/v1/ai/*`)**: HASP-native chat with full event taxonomy, run
    lifecycle,
      and PHI metadata.
    - **Anthropic-compat (`/v1/messages`)**: Drop-in replacement for
    `@anthropic-ai/sdk` —
      change only `baseURL`. All Gateway compliance checks (BAA, credits, PHI policy) apply.

    All requests require an API key (`Authorization: Bearer
    hasp_api_live_<key>`). See

    [Authentication](https://docs.usehasp.com/ai-api/authentication) for key
    management.
servers:
  - url: https://api.usehasp.com/v1
    description: Production
security:
  - http: []
paths:
  /chat/completions:
    post:
      tags:
        - ChatCompletions
      summary: >-
        Handle an OpenAI Chat Completions-compatible request, streaming or
        returning the assembled response
      operationId: v1.chat.completions
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionsRequest'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                anyOf:
                  - type: object
                    properties:
                      id:
                        type: string
                      object:
                        type: string
                        const: chat.completion
                      created:
                        type: integer
                      model: {}
                      choices:
                        type: array
                        prefixItems:
                          - type: object
                            properties:
                              index:
                                type: integer
                              message:
                                type: object
                                properties:
                                  role:
                                    type: string
                                    const: assistant
                                  content:
                                    type:
                                      - string
                                      - 'null'
                                  tool_calls:
                                    type: array
                                    items: {}
                                required:
                                  - role
                                  - content
                              finish_reason:
                                type: string
                                enum:
                                  - stop
                                  - tool_calls
                                  - length
                                  - content_filter
                            required:
                              - index
                              - message
                              - finish_reason
                        minItems: 1
                        maxItems: 1
                        additionalItems: false
                      usage:
                        type: object
                        properties:
                          prompt_tokens:
                            type: integer
                          completion_tokens:
                            type: integer
                          total_tokens:
                            type: integer
                        required:
                          - prompt_tokens
                          - completion_tokens
                          - total_tokens
                    required:
                      - id
                      - object
                      - created
                      - model
                      - choices
                      - usage
                  - type: string
            text/event-stream:
              schema:
                type: string
          headers:
            Transfer-Encoding:
              required: true
              schema:
                type: string
                enum:
                  - chunked
        '401':
          description: OpenAI-shaped error — bearer token missing, malformed, or revoked.
          content:
            application/json:
              schema:
                type: string
                examples:
                  - error:
                      message: Bearer token is missing, malformed, or revoked.
                      type: authentication_error
                      param: null
                      code: invalid_api_key
                      hasp_code: INVALID_API_KEY
        '403':
          $ref: '#/components/responses/AuthorizationException'
        '422':
          $ref: '#/components/responses/ValidationException'
        '429':
          description: OpenAI-shaped error — rate limit exceeded.
          content:
            application/json:
              schema:
                type: string
                examples:
                  - error:
                      message: Rate limit exceeded.
                      type: rate_limit_error
                      param: null
                      code: rate_limited
                      hasp_code: RATE_LIMITED
components:
  schemas:
    ChatCompletionsRequest:
      type: object
      description: >-
        Validates POST /v1/chat/completions (OpenAI-compat) per ADR-YGE00M.


        Accepts OpenAI's Chat Completions wire format:
        system/user/assistant/tool

        role messages, function-tool definitions, and tool_calls/tool_call_id
        for

        round-tripping tool results. `top_p`, `tool_choice`, and `stop` are
        wired

        into InferenceRequest's canonical `topP`/`toolChoice`/`stopSequences`

        fields (HASP-509); `user` is forwarded as `metadata.user_id`, a
        documented

        graceful degrade on this surface (see DirectProviderDriver::supports())
        —

        OpenAI's real API accepts it but HASP's OpenAI driver does not forward
        it

        upstream today. `n`, `frequency_penalty`, and `presence_penalty` are

        outside the cross-provider parameter model this DTO carries (no
        Anthropic

        analog) and remain validated for shape but otherwise ignored.
      properties:
        model:
          type: string
          maxLength: 100
        tool_choice:
          type:
            - string
            - 'null'
        max_tokens:
          type:
            - integer
            - 'null'
          minimum: 1
          maximum: 32000
        stream:
          type:
            - boolean
            - 'null'
        temperature:
          type:
            - number
            - 'null'
          minimum: 0
          maximum: 2
        top_p:
          type:
            - number
            - 'null'
          minimum: 0
          maximum: 1
        'n':
          type:
            - integer
            - 'null'
        frequency_penalty:
          type:
            - number
            - 'null'
          minimum: -2
          maximum: 2
        presence_penalty:
          type:
            - number
            - 'null'
          minimum: -2
          maximum: 2
        user:
          type:
            - string
            - 'null'
          maxLength: 255
        provider_extensions:
          type:
            - array
            - 'null'
          description: |-
            Escape hatch for provider-specific wire keys the canonical
            fields above don't (yet) model — see ADR-ZP99PX. No OpenAI driver
            wiring exists today (see DirectProviderDriver::supports()), so
            setting this is rejected with UNSUPPORTED_PARAMETER rather than
            silently dropped.
          items:
            type: string
        stop:
          type:
            - array
            - 'null'
          items:
            type: string
        messages:
          type: array
          items:
            type: object
            properties:
              role:
                type: string
                enum:
                  - system
                  - user
                  - assistant
                  - tool
              content:
                type:
                  - string
                  - 'null'
              name:
                type:
                  - string
                  - 'null'
                maxLength: 255
              tool_call_id:
                type:
                  - string
                  - 'null'
                maxLength: 255
              tool_calls:
                type:
                  - array
                  - 'null'
                items:
                  type: object
                  properties:
                    id:
                      type: string
                    type:
                      type: string
                      enum:
                        - function
                    function:
                      type: object
                      properties:
                        name:
                          type: string
                        arguments:
                          type: string
                      required:
                        - name
                        - arguments
                  required:
                    - id
                    - type
            required:
              - role
          minItems: 1
        tools:
          type:
            - array
            - 'null'
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - function
              function:
                type: object
                properties:
                  name:
                    type: string
                  description:
                    type:
                      - string
                      - 'null'
                  parameters:
                    type:
                      - object
                      - 'null'
                    description: A JSON Schema object describing the function's parameters.
                    additionalProperties: {}
                required:
                  - name
            required:
              - type
      required:
        - model
        - messages
      title: ChatCompletionsRequest
  responses:
    AuthorizationException:
      description: Authorization error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    ValidationException:
      description: Validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Errors overview.
              errors:
                type: object
                description: A detailed description of each field that failed validation.
                additionalProperties:
                  type: array
                  items:
                    type: string
            required:
              - message
              - errors
  securitySchemes:
    http:
      type: http
      scheme: bearer

````