glhf Chat Completions API

OpenAI-compatible chat completions endpoint that serves almost any open-source model from Hugging Face by passing the repository as hf:org/model. Supports streaming responses via Server-Sent Events when stream is set to true.

OpenAPI Specification

glhf-chat-openapi.yml Raw ↑
openapi: 3.0.1
info:
  title: glhf API
  description: >-
    OpenAI-compatible REST API for glhf (glhf.chat), a platform that runs almost
    any open-source large language model on demand. Models are selected by passing
    a Hugging Face repository identifier as hf:org/model. Only the endpoints
    documented for the glhf OpenAI-compatible surface are described here.
  termsOfService: https://glhf.chat
  contact:
    name: glhf
    url: https://glhf.chat
  version: '1.0'
servers:
  - url: https://glhf.chat/api/openai/v1
    description: glhf OpenAI-compatible base URL.
security:
  - bearerAuth: []
paths:
  /chat/completions:
    post:
      operationId: createChatCompletion
      tags:
        - Chat
      summary: Create a chat completion.
      description: >-
        Creates a model response for the given chat conversation. The model field
        must be a Hugging Face repository in the form hf:org/model (for example
        hf:meta-llama/Llama-3.3-70B-Instruct). When stream is true, partial message
        deltas are returned as Server-Sent Events terminated by a data: [DONE]
        message.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateChatCompletionRequest'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateChatCompletionResponse'
            text/event-stream:
              schema:
                $ref: '#/components/schemas/ChatCompletionChunk'
        '400':
          description: Bad request, for example a model identifier without a valid prefix.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized, missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /models:
    get:
      operationId: listModels
      tags:
        - Models
      summary: List available models.
      description: >-
        Lists the models available to the account in the OpenAI models response
        shape.
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListModelsResponse'
        '401':
          description: Unauthorized, missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        glhf API key passed as a Bearer token in the Authorization header. Keys
        are created at https://glhf.chat/users/settings/api.
  schemas:
    CreateChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: >-
            Hugging Face repository identifier in the form hf:org/model.
          example: hf:meta-llama/Llama-3.3-70B-Instruct
        messages:
          type: array
          description: A list of messages comprising the conversation so far.
          items:
            $ref: '#/components/schemas/ChatMessage'
        stream:
          type: boolean
          description: >-
            If true, partial message deltas are sent as Server-Sent Events.
          default: false
        temperature:
          type: number
          format: float
          description: Sampling temperature between 0 and 2.
        top_p:
          type: number
          format: float
          description: Nucleus sampling probability mass.
        max_tokens:
          type: integer
          description: Maximum number of tokens to generate in the completion.
        stop:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: Up to a few sequences where generation will stop.
        n:
          type: integer
          description: Number of completions to generate for each prompt.
        presence_penalty:
          type: number
          format: float
        frequency_penalty:
          type: number
          format: float
    ChatMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
        content:
          type: string
    CreateChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: chat.completion
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            $ref: '#/components/schemas/ChatCompletionChoice'
        usage:
          $ref: '#/components/schemas/Usage'
    ChatCompletionChoice:
      type: object
      properties:
        index:
          type: integer
        message:
          $ref: '#/components/schemas/ChatMessage'
        finish_reason:
          type: string
    ChatCompletionChunk:
      type: object
      description: >-
        A streamed chunk of a chat completion delivered as a Server-Sent Event
        when stream is true.
      properties:
        id:
          type: string
        object:
          type: string
          example: chat.completion.chunk
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              delta:
                $ref: '#/components/schemas/ChatMessage'
              finish_reason:
                type: string
                nullable: true
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
    ListModelsResponse:
      type: object
      properties:
        object:
          type: string
          example: list
        data:
          type: array
          items:
            $ref: '#/components/schemas/Model'
    Model:
      type: object
      properties:
        id:
          type: string
          example: hf:meta-llama/Llama-3.3-70B-Instruct
        object:
          type: string
          example: model
        created:
          type: integer
        owned_by:
          type: string
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string