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

# Create a chat completion

> 
An OpenAI-compatible chat completion endpoint that redacts PHI before the
model sees it and restores the real values in the answer.

```python
client = OpenAI(base_url="https://<host>/api/v1/llm", api_key="hpx_...")
client.chat.completions.create(model="<model>", messages=[...])
```

Per request: your message content is redacted (Malaysian IC/MRN/passport/phone,
names, emails, account numbers — clinical content such as ages, dates like
"day 3 post-op", vitals and dosages is preserved), the placeholders go to the
model, and the model's answer has your values substituted back. The mapping
lives only in the request's memory and is never stored.

Every response carries `redaction_receipt`, including `rehydration_complete`
and `unresolved_placeholder_count` — if the model altered our placeholders, the
receipt says so rather than returning residue silently.

**Tool calling** is supported: send OpenAI-style `tools`, receive `tool_calls`
with your values re-hydrated. Your `tool` role results are redacted on the way
out like any other message, and so are the arguments of an assistant turn you
send back.

**Not supported** (refused, not silently dropped): streaming while re-hydrating
(`stream` with `redact_only=false`), tools combined with `stream`, non-text
content parts, forcing a specific tool via `tool_choice`, and the deprecated
`functions`/`function_call` form.
    



## OpenAPI

````yaml /api/openapi-commercial.yaml post /api/v1/llm/chat/completions
openapi: 3.0.3
info:
  title: Healthproximate API
  version: 1.0.0
  description: >-
    DRG classification, OMOP vocabulary services and a PHI-safe LLM gateway.


    Generated by `manage.py export_commercial_openapi` from an explicit
    operation allowlist (`app/openapi_commercial.py`). An endpoint appears here
    because someone published it, never because it exists.
  contact:
    email: admin@valiancehealth.ai
servers:
  - url: https://api.v2.healthproximate.com
security: []
tags:
  - name: DRG
    description: MS-DRG classification from coded input, free clinical text, or FHIR.
  - name: Vocabulary
    description: OMOP concept search, coding, translation and hierarchy resolution.
  - name: Gateway
    description: >-
      PHI-safe LLM access. Text is redacted before any model sees it and
      re-hydrated in the answer, and every response carries a receipt.
paths:
  /api/v1/llm/chat/completions:
    post:
      tags:
        - Gateway
      summary: Create a chat completion
      description: >-

        An OpenAI-compatible chat completion endpoint that redacts PHI before
        the

        model sees it and restores the real values in the answer.


        ```python

        client = OpenAI(base_url="https://<host>/api/v1/llm", api_key="hpx_...")

        client.chat.completions.create(model="<model>", messages=[...])

        ```


        Per request: your message content is redacted (Malaysian
        IC/MRN/passport/phone,

        names, emails, account numbers — clinical content such as ages, dates
        like

        "day 3 post-op", vitals and dosages is preserved), the placeholders go
        to the

        model, and the model's answer has your values substituted back. The
        mapping

        lives only in the request's memory and is never stored.


        Every response carries `redaction_receipt`, including
        `rehydration_complete`

        and `unresolved_placeholder_count` — if the model altered our
        placeholders, the

        receipt says so rather than returning residue silently.


        **Tool calling** is supported: send OpenAI-style `tools`, receive
        `tool_calls`

        with your values re-hydrated. Your `tool` role results are redacted on
        the way

        out like any other message, and so are the arguments of an assistant
        turn you

        send back.


        **Not supported** (refused, not silently dropped): streaming while
        re-hydrating

        (`stream` with `redact_only=false`), tools combined with `stream`,
        non-text

        content parts, forcing a specific tool via `tool_choice`, and the
        deprecated

        `functions`/`function_call` form.
            
      operationId: v1_llm_chat_completions_create
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequestRequest'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequestRequest'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequestRequest'
        required: true
      responses:
        '200':
          description: chat.completion with a redaction receipt attached
        '400':
          description: Invalid request, or model not approved
        '401':
          description: Authentication required
        '429':
          description: Rate limit or spend limit reached
        '503':
          description: Redaction failed — request refused
      security:
        - gateway_bearer_auth: []
components:
  schemas:
    ChatCompletionRequestRequest:
      type: object
      properties:
        model:
          type: string
          minLength: 1
          description: >-
            A model id from the registry. External keys may only use models
            approved for PHI traffic.
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessageRequest'
        max_tokens:
          type: integer
          maximum: 32000
          minimum: 1
          default: 1024
        temperature:
          type: number
          format: double
          nullable: true
        top_p:
          type: number
          format: double
          nullable: true
        stop:
          type: string
          nullable: true
          minLength: 1
        stream:
          type: boolean
          default: false
        redact_only:
          type: boolean
          default: false
          description: >-
            Return the model's answer WITHOUT substituting your values back
            (placeholders remain). Required if you want streaming, and useful
            when the answer is going somewhere that should not hold PHI.
        tools:
          type: array
          items:
            type: object
            additionalProperties: {}
          description: >-
            OpenAI-style function tools. Forwarded to the model; returned
            tool_calls come back with your values re-hydrated.
        tool_choice:
          description: >-
            "auto" (default) or "none". Forcing a specific call ("required", or
            a named function) is refused rather than downgraded to "auto", so a
            forced call never appears to have been honoured when it was not.
        conversation_key:
          type: string
          description: >-
            Supply the same value across turns so a given person keeps the same
            placeholder; multi-turn clients resend history and renaming
            mid-conversation confuses the model.
          maxLength: 200
      required:
        - messages
        - model
    ChatMessageRequest:
      type: object
      properties:
        role:
          $ref: '#/components/schemas/ChatMessageRoleEnum'
        content:
          type: string
          nullable: true
          maxLength: 100000
        tool_calls:
          type: array
          items:
            type: object
            additionalProperties: {}
        tool_call_id:
          type: string
          minLength: 1
          description: >-
            Required on a `tool` message: it matches the result to the call that
            asked for it.
          maxLength: 200
      required:
        - role
    ChatMessageRoleEnum:
      enum:
        - system
        - user
        - assistant
        - tool
      type: string
      description: |-
        * `system` - system
        * `user` - user
        * `assistant` - assistant
        * `tool` - tool
  securitySchemes:
    gateway_bearer_auth:
      type: http
      scheme: bearer
      description: >-
        Your hpx_ API key as a Bearer token, so OpenAI-compatible SDKs work
        unmodified. X-API-Key and first-party JWTs are also accepted.

````