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

> Create a new span for a tool/function call. See [Spans](https://docs.galtea.ai/sdk/api/span/service). These endpoints serve spans, the steps inside a trace. Their REST path `/traces` keeps the old name of this entity.

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


## OpenAPI

````yaml /v5.20/openapi.json post /traces
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:
  /traces:
    post:
      tags:
        - spans
      summary: Create span
      description: >-
        Create a new span for a tool/function call. See
        [Spans](https://docs.galtea.ai/sdk/api/span/service). These endpoints
        serve spans, the steps inside a trace. Their REST path `/traces` keeps
        the old name of this entity.
      operationId: createTrace
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - inferenceResultId
                - name
              properties:
                inferenceResultId:
                  type: string
                  example: ir_123
                name:
                  type: string
                  example: Example Name
                type:
                  type: string
                  enum:
                    - SPAN
                    - GENERATION
                    - EVENT
                    - AGENT
                    - TOOL
                    - CHAIN
                    - RETRIEVER
                    - EVALUATOR
                    - EMBEDDING
                    - GUARDRAIL
                  description: >-
                    Type of span. A value outside this list is not dropped, it
                    is normalized to one of these types, and the original label
                    is kept in the span's metadata under
                    `galtea.span.original_type`.
                inputData:
                  type: object
                outputData:
                  oneOf:
                    - type: object
                    - type: string
                error:
                  type: string
                  example: Error message
                latencyMs:
                  type: number
                metadata:
                  type: object
      responses:
        '200':
          description: Span created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Trace'
        '400':
          description: >-
            A field is invalid, or a `file` part of `inputData` or `outputData`
            names a Galtea file the rules refuse: a file of another
            organization, more than 20 files or 20 MB, or a refused type.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    Trace:
      type: object
      description: >-
        A span: one step inside a trace, such as a tool call, a retrieval or an
        LLM call. The schema name and the `/traces` path still carry the old
        name of this entity, "trace". The parent trace is `inferenceResultId`;
        the `parentTraceId` field is the parent span, not the trace. Span ids
        start with `trace_`, so a `trace_` id belongs here and never to a trace.
      properties:
        id:
          type: string
          example: trace_123
        inferenceResultId:
          type: string
          example: ir_123
        name:
          type: string
          example: fetch_user_data
        type:
          type: string
          enum:
            - SPAN
            - GENERATION
            - EVENT
            - AGENT
            - TOOL
            - CHAIN
            - RETRIEVER
            - EVALUATOR
            - EMBEDDING
            - GUARDRAIL
          nullable: true
          example: TOOL
        description:
          type: string
          nullable: true
          example: Fetches user data from the database by ID
          description: Human-readable description of the operation. Maximum 1MB.
        inputData:
          type: object
          nullable: true
          example:
            user_id: '123'
          description: Input parameters passed to the operation
        outputData:
          oneOf:
            - type: object
            - type: string
          nullable: true
          example:
            name: John Doe
            email: john@example.com
          description: >-
            Result returned by the operation. Usually an object; a plain string
            for retrieval-context spans
        error:
          type: string
          nullable: true
          example: Connection timeout
          description: Error message if failed
        latencyMs:
          type: number
          nullable: true
          example: 45.5
          description: Execution time in milliseconds
        metadata:
          type: object
          nullable: true
          example:
            model: gpt-4
            temperature: 0.7
          description: Additional custom metadata
        parentTraceId:
          type: string
          nullable: true
          example: trace_parent_123
          description: ID of parent span for hierarchical relationships
        startTime:
          type: string
          format: date-time
          nullable: true
        endTime:
          type: string
          format: date-time
          nullable: true
        createdAt:
          type: string
          format: date-time
        deletedAt:
          type: string
          format: date-time
          nullable: true
        modelId:
          type: string
          nullable: true
          readOnly: true
          example: model_123
          description: >-
            The model that answered this LLM call, found by name when the span
            was ingested. Galtea tries the response model name, then the request
            model name, each through the model name rule: the name itself, then
            without its provider prefix, then without a trailing date, then with
            a provider prefix added. From 2026-11-19 the last two steps exist: a
            name with a date, or with no provider prefix, links a model where it
            linked none (a span named 'mistral-small-2603' links
            'mistral/mistral-small-2603'). From 2026-11-19 too, the response
            model name goes through every step before the request model name is
            tried (a span with response 'openai/gpt-4o' and request
            'gpt-4o-mini' links 'gpt-4o'), and a span whose metadata holds a
            request model name but no span model name (a span that did not come
            from OTLP) is looked up by it. Null when no live model of the
            organization, or global model, matched. Deleting the model keeps it,
            so it can name a deleted model.
        modelName:
          type: string
          nullable: true
          readOnly: true
          example: gpt-4o-mini
          description: The model name the span reported, whether or not it matched a model.
        inputTokens:
          type: integer
          nullable: true
          readOnly: true
          example: 100
          description: >-
            Input tokens the LLM call reported, cached input included. Null
            without `evaluation.readInference` on the product.
        outputTokens:
          type: integer
          nullable: true
          readOnly: true
          example: 50
          description: >-
            Output tokens the LLM call reported. Null without
            `evaluation.readInference` on the product.
        cacheReadInputTokens:
          type: integer
          nullable: true
          readOnly: true
          example: 20
          description: >-
            Input tokens the LLM call read from the cache, a part of
            `inputTokens` priced at the cache-read rate. A count above
            `inputTokens` is taken as counted apart and flagged in the metadata.
            Null without `evaluation.readInference` on the product.
        tokens:
          type: integer
          nullable: true
          readOnly: true
          example: 170
          description: >-
            Sum of the input and output tokens, so cached input counts once,
            plus the cache read when the source counted it apart from the input.
            Null without `evaluation.readInference` on the product.
        costPerInputToken:
          type: number
          nullable: true
          readOnly: true
          example: 0.00001
          description: >-
            Price of one input token, frozen at ingest from the model of this
            call, or from the version model when the span names no model. From
            2026-11-19 a span whose metadata holds a request model name but no
            span model name (a span that did not come from OTLP) is priced at
            the model that name links, and keeps the version model when it links
            none. Null when the model name of the span links to nothing (an OTLP
            span takes its model name from the response model, else the request
            model), or the model has no price. Null without
            `evaluation.readInference` on the product.
        costPerOutputToken:
          type: number
          nullable: true
          readOnly: true
          example: 0.00003
          description: >-
            Price of one output token, frozen at ingest like costPerInputToken.
            Null without `evaluation.readInference` on the product.
        costPerCacheReadInputToken:
          type: number
          nullable: true
          readOnly: true
          example: 0.000005
          description: >-
            Price of one cache-read token, frozen at ingest like
            costPerInputToken. Null without `evaluation.readInference` on the
            product.
        cost:
          type: number
          nullable: true
          readOnly: true
          example: 0.0026
          description: >-
            Cost of this call at the frozen rates. Null when no rates were
            found. A turn's cost sums the costs of the spans it counts. A call
            counts once for each side, input and output, from the deepest span
            that reports it. Two sibling spans that report the same call both
            count, as a Mistral SDK span and its `llm_call_details` event do. A
            span that loses one side to a span below is priced again for the
            side it keeps. Null without `evaluation.readInference` on the
            product.
    Error:
      type: object
      properties:
        error:
          type: string
          example: Error type
        message:
          type: string
          example: Error message description
  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.