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

> ## Agent Instructions
> Call https://api.feyn.ai only; the hosts behind it are not public.
> Authenticate with a workspace API key in the Authorization header: `Authorization: Bearer fn_...`. Keep keys server-side.
> For chat completions, use the official OpenAI SDK with base_url https://api.feyn.ai/v1 and a model ID from GET /v1/models.
> On 429, wait for the Retry-After header before retrying. Failed requests are not charged.

# Create a chat completion

> OpenAI-compatible Chat Completions. Any field the OpenAI format accepts is passed through to the model.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: Feyn API
  version: 1.0.0
  description: Fine-tuned models, chat completions, traces and scores on api.feyn.ai.
servers:
  - url: https://api.feyn.ai
security:
  - bearerAuth: []
paths:
  /v1/chat/completions:
    post:
      summary: Create a chat completion
      description: >-
        OpenAI-compatible Chat Completions. Any field the OpenAI format accepts
        is passed through to the model.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
              additionalProperties: true
              properties:
                model:
                  type: string
                  description: A model id from `GET /v1/models`.
                  example: your-workspace-model
                messages:
                  type: array
                  items:
                    type: object
                    required:
                      - role
                    properties:
                      role:
                        type: string
                        enum:
                          - system
                          - user
                          - assistant
                          - tool
                      content:
                        type: string
                stream:
                  type: boolean
                  description: Stream the response as server-sent events.
                temperature:
                  type: number
                max_tokens:
                  type: integer
            example:
              model: your-workspace-model
              messages:
                - role: user
                  content: hi
      responses:
        '200':
          description: >-
            A chat completion in the OpenAI format (or an event stream when
            `stream` is true).
          content:
            application/json:
              schema:
                type: object
            text/event-stream:
              schema:
                type: string
        '400':
          $ref: '#/components/responses/Error'
        '401':
          $ref: '#/components/responses/Error'
        '402':
          $ref: '#/components/responses/Error'
        '403':
          $ref: '#/components/responses/Error'
        '404':
          $ref: '#/components/responses/Error'
        '429':
          $ref: '#/components/responses/Error'
        '502':
          $ref: '#/components/responses/Error'
        '503':
          $ref: '#/components/responses/Error'
components:
  responses:
    Error:
      description: An error. See the errors guide for each status.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
              enum:
                - invalid_request_error
                - auth_error
                - billing_error
                - permission_error
                - rate_limit_error
                - api_error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: A workspace API key (`fn_...`).

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.