> ## 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.

# Write a trace

> Upsert a trace on `traceKey` within the project.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/traces
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/traces:
    post:
      summary: Write a trace
      description: Upsert a trace on `traceKey` within the project.
      parameters:
        - name: X-Feyn-Project
          in: header
          required: true
          description: The project's key (`projectKey`).
          schema:
            type: string
          example: inbox-triage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Trace'
      responses:
        '201':
          $ref: '#/components/responses/Id'
        '400':
          $ref: '#/components/responses/Error'
        '401':
          $ref: '#/components/responses/Error'
        '503':
          $ref: '#/components/responses/Error'
components:
  schemas:
    Trace:
      type: object
      required:
        - traceKey
        - messages
        - startedAt
      properties:
        traceKey:
          type: string
          description: Your id for the run; writes with the same key update one trace.
        modelKey:
          type: string
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        output:
          type: string
        reasoning:
          type: string
        cost:
          type: number
          description: USD.
        latency:
          type: number
          description: Milliseconds.
        status:
          type: integer
          description: The provider's HTTP status.
        metadata:
          type: object
          additionalProperties:
            type:
              - string
              - number
              - boolean
          description: Flat key-value pairs, stored as strings.
        startedAt:
          type: number
          description: Unix milliseconds.
        completedAt:
          type: number
          description: Unix milliseconds.
      example:
        traceKey: run_123:decide
        messages:
          - role: user
            content: 'Subject: Invoice overdue'
          - role: assistant
            content: notify
        output: notify
        latency: 491
        status: 200
        metadata:
          workflow_run_id: wf_88
        startedAt: 1726000000000
    Message:
      type: object
      required:
        - role
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
        content:
          type: string
        reasoning:
          type: string
          description: Assistant only.
        toolCalls:
          type: array
          description: >-
            Assistant only. OpenAI `tool_calls` and AI SDK tool-call parts are
            also accepted.
          items:
            type: object
            properties:
              id:
                type: string
              name:
                type: string
              arguments:
                type: string
                description: A JSON string.
        toolCallId:
          type: string
          description: Tool results only.
        name:
          type: string
          description: Tool name, on tool results.
    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
  responses:
    Id:
      description: The stored row's id.
      content:
        application/json:
          schema:
            type: object
            properties:
              id:
                type: string
    Error:
      description: An error. See the errors guide for each status.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/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.