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

# Create trace

> Create a new trace. Identify the session with exactly one of `sessionId` or `sessionCustomId`. With `sessionCustomId` (your own conversation id) an existing session with that custom id is found and appended to: provide either `versionId` or `productId` as the anchor (if both are given, `versionId` wins). The session must already exist — create it first through the sessions API with that `custom_id`. If no matching session exists, the call is rejected with a 400. See [Traces](https://docs.galtea.ai/concepts/product/version/session/trace). The REST path `/inferenceResults` and the `inferenceResult*` JSON fields keep the old name of this entity.


> [!WARNING]
>
> You are reading the docs of Galtea 5.22. [Read this page in the latest version](https://docs.galtea.ai/api-reference/traces/create-trace.md).


## OpenAPI

````yaml /v5.22/openapi.json post /inferenceResults
openapi: 3.0.0
info:
  version: 1.0.0
  title: Product Management Service API
  description: API documentation for Product Management Service
  contact:
    name: Galtea AI
servers:
  - url: https://api.galtea.ai
security:
  - bearerAuth: []
tags: []
externalDocs:
  description: Galtea Platform Documentation
  url: https://docs.galtea.ai
paths:
  /inferenceResults:
    post:
      tags:
        - traces
      summary: Create trace
      description: >
        Create a new trace. Identify the session with exactly one of `sessionId`
        or `sessionCustomId`. With `sessionCustomId` (your own conversation id)
        an existing session with that custom id is found and appended to:
        provide either `versionId` or `productId` as the anchor (if both are
        given, `versionId` wins). The session must already exist — create it
        first through the sessions API with that `custom_id`. If no matching
        session exists, the call is rejected with a 400. See
        [Traces](https://docs.galtea.ai/concepts/product/version/session/trace).
        The REST path `/inferenceResults` and the `inferenceResult*` JSON fields
        keep the old name of this entity.
      operationId: createInferenceResult
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                sessionId:
                  type: string
                  description: ID of the session. Provide this or `sessionCustomId`.
                  example: session_123
                sessionCustomId:
                  type: string
                  description: >
                    Your own conversation id. An existing session with this
                    custom id is found and appended to; if none matches the call
                    returns a 400, so create the session first through the
                    sessions API. Requires `versionId` or `productId`. Provide
                    this or `sessionId`.
                  example: my-conversation-42
                versionId:
                  type: string
                  description: >
                    Version anchor for the `sessionCustomId` lookup. Provide
                    this or `productId`; if both are given, `versionId` wins.
                  example: ver_123
                productId:
                  type: string
                  description: >
                    Product anchor for the `sessionCustomId` lookup when no
                    `versionId` is given: the existing session with that custom
                    id is found across the product's versions.
                  example: prod_123
                userId:
                  type: string
                  nullable: true
                  description: ID of the user
                  example: user_123
                index:
                  type: integer
                  description: Index of the trace
                  example: 0
                status:
                  type: string
                  enum:
                    - PENDING
                    - GENERATED
                    - FAILED
                    - SKIPPED
                  description: Status of the trace
                error:
                  type: string
                  nullable: true
                  description: >-
                    Error message explaining why this trace failed or was
                    skipped
                input:
                  type: object
                  nullable: true
                  description: >-
                    Structured input data. For plain text, use { user_message:
                    "..." }. Each element of a `content` array is read on its
                    own. A file part is a Galtea file when its uri names a
                    Galtea storage key (`files/<organization>/<32
                    hex>.<extension>`, on any host): it is stored signature-free
                    and checked as on a test case input (at most 20 files and 20
                    MB by default, an accepted file type, a file of this
                    organization), otherwise 400. A Galtea file missing from
                    storage is stored signature-free without its sizeBytes, and
                    every other element as sent. With
                    `INLINE_MEDIA_COPY_ENABLED` on, a binary file of 1,024
                    base64 characters or more, held in a data URI or in the byte
                    field of a provider object, is stored as a Galtea file token
                    instead.
                actualOutput:
                  oneOf:
                    - type: string
                    - type: object
                  nullable: true
                  description: >-
                    Agent output. Plain text by default (the scored scalar); an
                    envelope { assistant_message, content: [{ type, uri,
                    transcript }] } carries audio or file parts. A file part
                    with a non-empty uri is a file, and an answer that is only
                    files needs no scalar. A file element with no uri belongs to
                    the customer: it is stored as sent beside a scalar, and
                    refused without one. With `INLINE_MEDIA_COPY_ENABLED` on, a
                    binary file of 1,024 base64 characters or more, held in a
                    data URI or in the byte field of a provider object, is
                    stored as a Galtea file token instead.
                  example: Model response text
                retrievalContext:
                  type: string
                  nullable: true
                  description: Retrieval context information
                  example: Retrieved context document
                latency:
                  type: number
                  nullable: true
                  description: Latency in milliseconds
                inputTokens:
                  type: integer
                  nullable: true
                  description: >-
                    Number of input tokens sent to the model, cached input
                    included. At most 2147483647, else 400.
                outputTokens:
                  type: integer
                  nullable: true
                  description: Number of output tokens. At most 2147483647, else 400.
                cacheReadInputTokens:
                  type: integer
                  nullable: true
                  description: >-
                    Number of cache read input tokens, a part of the input
                    tokens. At most 2147483647, else 400.
                tokens:
                  type: integer
                  nullable: true
                  description: Total number of tokens. At most 2147483647, else 400.
                costPerInputToken:
                  type: number
                  nullable: true
                  description: Cost per input token
                costPerOutputToken:
                  type: number
                  nullable: true
                  description: Cost per output token
                costPerCacheReadInputToken:
                  type: number
                  nullable: true
                  description: Cost per cache read input token
                cost:
                  type: number
                  nullable: true
                  description: Total cost
                conversationSimulatorVersion:
                  type: string
                  nullable: true
                  description: Version of the conversation simulator
      responses:
        '201':
          description: Trace created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InferenceResult'
        '400':
          description: >-
            Invalid body, including a Galtea file on the input or output that
            breaks a file rule
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    InferenceResult:
      type: object
      description: >-
        A trace: one conversation turn, holding the input and the agent output.
        The schema name, the `/inferenceResults` path and every
        `inferenceResult*` field still carry the old name of this entity,
        "inference result". Only the wording changed so far; the wire contract
        is renamed in a later API release.
      properties:
        id:
          type: string
          example: ir_123
        sessionId:
          type: string
          example: session_123
        userId:
          type: string
          nullable: true
          example: user_123
        index:
          type: integer
          example: 0
          description: Order index within the session
        status:
          type: string
          enum:
            - PENDING
            - GENERATED
            - FAILED
            - SKIPPED
          example: PENDING
        error:
          type: string
          nullable: true
          description: Error message explaining why this trace failed or was skipped
          example: null
        input:
          type: object
          nullable: true
          description: >-
            Structured input data. For plain text input, format is {
            user_message: "..." }. A `content` array of parts (audio or file)
            can sit beside an optional `user_message`. Each element of a
            `content` array is read on its own. A file part is a Galtea file
            when its uri names a Galtea storage key (`files/<organization>/<32
            hex>.<extension>`, on any host): it is stored signature-free and
            checked as on a test case input (at most 20 files and 20 MB by
            default, an accepted file type, a file of this organization),
            otherwise 400. A Galtea file missing from storage is stored
            signature-free without its sizeBytes, and every other element as
            sent. With `INLINE_MEDIA_COPY_ENABLED` on, a binary file of 1,024
            base64 characters or more, held in a data URI or in the byte field
            of a provider object, is stored as a Galtea file token instead. A
            metric scores a Galtea file only when its judge model reads that
            kind of file (PNG, JPEG, WebP, GIF or PDF, or a text file (TXT, CSV,
            Markdown, JSON, XML or HTML), read as its text); any other metric
            that reads this side is skipped, except a human evaluation or
            self-hosted one, and the reason names the file.
          example:
            user_message: User input text
        actualOutput:
          oneOf:
            - type: string
            - type: object
          nullable: true
          description: >-
            The agent turn output. Plain text by default (the scored scalar). An
            envelope { assistant_message, content: [...] } carries a `content`
            array of parts (audio or file) beside an optional
            `assistant_message` — the scored scalar stays the canonical
            transcript, and an answer that is only a file carries no scalar at
            all. A metric scores a Galtea file only when its judge model reads
            that kind of file (PNG, JPEG, WebP, GIF or PDF, or a text file (TXT,
            CSV, Markdown, JSON, XML or HTML), read as its text); any other
            metric that reads this side is skipped, except a human evaluation or
            self-hosted one, and the reason names the file.
          example: Model response
        latency:
          type: integer
          nullable: true
          example: 150
        inputTokens:
          type: integer
          nullable: true
          example: 100
        outputTokens:
          type: integer
          nullable: true
          example: 50
        cacheReadInputTokens:
          type: integer
          nullable: true
          example: 20
        tokens:
          type: integer
          nullable: true
          example: 150
          description: Total tokens
        costPerInputToken:
          type: number
          nullable: true
          example: 0.00001
        costPerOutputToken:
          type: number
          nullable: true
          example: 0.00003
        costPerCacheReadInputToken:
          type: number
          nullable: true
          example: 0.000005
        cost:
          type: number
          nullable: true
          example: 0.001
        creditsUsed:
          type: integer
          nullable: true
          example: 1
        droppedSpanCount:
          type: integer
          nullable: true
          example: 2
          description: >-
            How many spans sent with this trace were refused, for example a span
            with an empty name or a negative latency. Null means none were
            refused.
        endUser:
          type: string
          nullable: true
          readOnly: true
          example: customer_42
          description: >-
            The end user of this trace, set by OTel ingest from its own spans.
            Read-only. The session holds the first end user of all its traces.
        streamTruncated:
          type: boolean
          readOnly: true
          example: false
          description: >-
            True when the agent's streamed reply closed before the terminal
            event of its endpoint connection, so the output is partial.
            Read-only.
        timeToFirstToken:
          type: number
          nullable: true
          readOnly: true
          example: 412.5
          description: >-
            Milliseconds from the start of the request to the agent to the first
            chunk of its streamed reply that carried text. Null when the reply
            did not stream or carried no text, and for a user without the
            `evaluation.readInference` permission. Read-only.
        conversationSimulatorVersion:
          type: string
          nullable: true
          example: 1.0.0
        traceId:
          type: string
          nullable: true
          example: a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4
          description: >-
            W3C trace ID Galtea sends in the `traceparent` header on this Direct
            Inference turn. Stored when the turn starts. This is the
            OpenTelemetry trace id, not the id of this Galtea trace, which is
            `id`.
        createdAt:
          type: string
          format: date-time
        deletedAt:
          type: string
          format: date-time
          nullable: true
        comments:
          type: array
          description: Free-form reviewer annotations on this turn, oldest first.
          items:
            $ref: '#/components/schemas/Comment'
    Error:
      type: object
      properties:
        error:
          type: string
          example: NotFound
          description: >-
            The HTTP status name in PascalCase, such as `BadRequest` or
            `NotFound`.
        message:
          type: string
          example: Product not found
          description: What went wrong, for a person.
      required:
        - error
        - message
    Comment:
      type: object
      properties:
        id:
          type: string
          example: comment_123
        inferenceResultId:
          type: string
          example: inferenceResult_123
        text:
          type: string
          example: Agent hallucinated the price.
        tags:
          type: array
          items:
            type: string
          example:
            - hallucination
            - tone
        userId:
          type: string
          nullable: true
          example: user_123
        userName:
          type: string
          nullable: true
          example: John Doe
        userEmail:
          type: string
          nullable: true
          format: email
          example: user@example.com
        createdAt:
          type: string
          format: date-time
      required:
        - id
        - inferenceResultId
        - text
        - tags
        - userId
        - userName
        - userEmail
        - createdAt
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        API key authorization. Pass your API key in the Authorization header as
        a Bearer token. Both new (`gsk_*`) and legacy (`gsk-`) API keys are
        accepted, e.g. `Authorization: Bearer gsk_...` or `Authorization: Bearer
        gsk-...`.

````

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