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

# Create chat completion

> OpenAI-compatible chat completion endpoint with user context



## OpenAPI

````yaml /api-reference/openapi.yaml post /users/{user_id}/chat/completions
openapi: 3.1.0
info:
  title: ONVY Health API
  description: >-
    AI-powered holistic health services API with data merging and metrics
    calculation
  version: 1.0.0
  contact:
    name: ONVY Support
    email: support@onvy.health
    url: https://onvy.health
  license:
    name: Proprietary
    url: https://onvy.health/terms
servers:
  - url: https://api.onvy.health
    description: Public API
security:
  - bearerAuth: []
tags:
  - name: static
    description: Static configuration endpoints
  - name: users
    description: User management
  - name: baselines
    description: User baseline metrics
  - name: daily-records
    description: Daily health records
  - name: chat
    description: AI chat completions
  - name: facts
    description: User facts for individualization
  - name: activities
    description: User activities (workouts and mindfulness sessions)
  - name: ai-summaries
    description: |
      AI-generated summaries. This is how ONVY exposes domain-specific
      insights such as meal nutrition analysis, sleep insights, workouts,
      and daily, weekly, nutrition, trend, and impact analysis. Most
      summary types are system-generated; the public create surface
      currently accepts `type=meal`.
  - name: custom-records
    description: Custom records and types
  - name: meals
    description: Nutrition meal tracking
paths:
  /users/{user_id}/chat/completions:
    post:
      tags:
        - chat
      summary: Create chat completion
      description: OpenAI-compatible chat completion endpoint with user context
      operationId: createChatCompletion
      parameters:
        - $ref: '#/components/parameters/UserIdParam'
      requestBody:
        description: Chat completion request
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: Chat completion created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    UserIdParam:
      name: user_id
      in: path
      required: true
      description: User ID (e.g., google_104940819145861640201)
      schema:
        type: string
  schemas:
    ChatCompletionRequest:
      title: ChatCompletionRequest
      type: object
      required:
        - messages
      properties:
        messages:
          type: array
          items:
            type: object
            required:
              - role
              - content
            properties:
              role:
                type: string
                enum:
                  - system
                  - user
                  - assistant
              content:
                type: string
        model:
          type: string
          description: Model to use for completion
        temperature:
          type: number
          minimum: 0
          maximum: 2
        max_tokens:
          type: integer
          minimum: 1
        stream:
          type: boolean
          description: Whether to stream the response
        top_p:
          type: number
          minimum: 0
          maximum: 1
        frequency_penalty:
          type: number
          minimum: -2
          maximum: 2
        presence_penalty:
          type: number
          minimum: -2
          maximum: 2
        exclude_context:
          type: array
          description: >
            Context sections to omit from automatic enrichment:

            - all: skip all enrichment (system prompt + knowledge); keep
            messages unchanged

            - knowledge: skip retrieval of knowledge base context and links

            - scores: omit recent score summaries from the system prompt

            - workouts: omit recent workout/activity summaries

            - baselines: omit baseline medians/ranges from the system prompt

            - facts: omit long-term personal facts/profile information

            - notes: omit helper notes explaining metrics and data columns

            - language: omit user language; fall back to default
          items:
            type: string
            enum:
              - all
              - knowledge
              - scores
              - workouts
              - baselines
              - facts
              - notes
              - language
    ChatCompletionResponse:
      title: ChatCompletionResponse
      type: object
      required:
        - id
        - object
        - created
        - model
        - choices
      properties:
        id:
          type: string
          description: Unique identifier for the completion
        object:
          type: string
        created:
          type: integer
          description: Unix timestamp
        model:
          type: string
          description: Model used for the completion
        choices:
          type: array
          items:
            type: object
            required:
              - index
              - message
              - finish_reason
            properties:
              index:
                type: integer
              message:
                type: object
                properties:
                  role:
                    type: string
                  content:
                    type: string
              finish_reason:
                type:
                  - string
                  - 'null'
                enum:
                  - stop
                  - length
                  - content_filter
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
    ValidationError:
      type: object
      title: ValidationError
      required:
        - error
      properties:
        error:
          type: string
          minLength: 1
      additionalProperties: false
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationError'
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationError'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: OAuth bearer token for Health API authentication

````