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

# Create traces spans

> Requires scopes: traces:write



## OpenAPI

````yaml /api-reference/openapi.json post /api/traces/{id}/spans
openapi: 3.1.0
info:
  title: EvalGate API
  version: 3.7.6
  description: EvalGate API. See docs/api-contract.md for stability commitments.
servers:
  - url: https://evalgate.com
    description: Production
  - url: http://localhost:3000
    description: Local
security: []
paths:
  /api/traces/{id}/spans:
    post:
      tags:
        - traces
      summary: Create traces spans
      description: 'Requires scopes: traces:write'
      operationId: post_traces_id_spans
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PostApiTracesIdSpansRequest'
      responses:
        '201':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PostApiTracesIdSpansResponse201ApplicationJson
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
      security:
        - bearerAuth:
            - traces:write
components:
  schemas:
    PostApiTracesIdSpansRequest:
      type: object
      properties:
        name:
          type: string
        input:
          $ref: '#/components/schemas/JsonValue'
        type:
          type: string
        metadata:
          $ref: '#/components/schemas/JsonValue'
        durationMs:
          oneOf:
            - type: 'null'
            - type: number
        spanId:
          type: string
        evaluationRunId:
          oneOf:
            - type: 'null'
            - type: number
        output:
          $ref: '#/components/schemas/JsonValue'
        parentSpanId:
          type: string
        startTime:
          type: string
        endTime:
          type: string
      additionalProperties: false
      required:
        - name
    PostApiTracesIdSpansResponse201ApplicationJson:
      type: object
      properties:
        input:
          oneOf:
            - type: 'null'
            - type: string
        type:
          type: string
        id:
          type: number
        name:
          type: string
        createdAt:
          type: string
          format: date-time
        metadata:
          oneOf:
            - type: 'null'
            - type: object
              properties:
                model:
                  type: string
                provider:
                  oneOf:
                    - type: string
                      enum:
                        - custom
                    - type: string
                      enum:
                        - meta
                    - type: string
                      enum:
                        - openai
                    - type: string
                      enum:
                        - anthropic
                    - type: string
                      enum:
                        - google
                    - type: string
                      enum:
                        - azure_openai
                    - type: string
                      enum:
                        - mistral
                    - type: string
                      enum:
                        - cohere
                    - type: string
                      enum:
                        - amazon
                    - type: string
                      enum:
                        - trace_linked
                tokenCount:
                  type: number
                cost:
                  type: number
                temperature:
                  type: number
                tokens:
                  type: number
                latencyMs:
                  type: number
                language:
                  type: string
                documentLength:
                  type: number
                cacheHit:
                  oneOf:
                    - type: boolean
                      enum:
                        - false
                    - type: boolean
                      enum:
                        - true
              additionalProperties: false
        provider:
          oneOf:
            - type: 'null'
            - type: string
        durationMs:
          oneOf:
            - type: 'null'
            - type: number
        traceId:
          type: number
        spanId:
          type: string
        evaluationRunId:
          oneOf:
            - type: 'null'
            - type: number
        inputHash:
          oneOf:
            - type: 'null'
            - type: string
        output:
          oneOf:
            - type: 'null'
            - type: string
        model:
          oneOf:
            - type: 'null'
            - type: string
        parentSpanId:
          oneOf:
            - type: 'null'
            - type: string
        startTime:
          oneOf:
            - type: 'null'
            - type: string
              format: date-time
        endTime:
          oneOf:
            - type: 'null'
            - type: string
              format: date-time
        tokenCount:
          oneOf:
            - type: 'null'
            - type: number
      additionalProperties: false
      required:
        - input
        - type
        - id
        - name
        - createdAt
        - metadata
        - provider
        - durationMs
        - traceId
        - spanId
        - evaluationRunId
        - inputHash
        - output
        - model
        - parentSpanId
        - startTime
        - endTime
        - tokenCount
    JsonValue:
      oneOf:
        - type: 'null'
        - type: boolean
        - type: number
        - type: string
        - type: array
          items:
            $ref: '#/components/schemas/JsonValue'
        - type: object
          additionalProperties:
            $ref: '#/components/schemas/JsonValue'
    ApiError:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - UNAUTHORIZED
                - FORBIDDEN
                - NOT_FOUND
                - VALIDATION_ERROR
                - RATE_LIMITED
                - CONFLICT
                - INTERNAL_ERROR
                - SERVICE_UNAVAILABLE
                - QUOTA_EXCEEDED
                - NO_ORG_MEMBERSHIP
                - CROSS_ORG_REFERENCE
                - INCOMPLETE
                - MALFORMED
            message:
              type: string
            details: {}
            requestId:
              type: string
              format: uuid
          required:
            - code
            - message
      required:
        - error
  responses:
    ValidationError:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    Conflict:
      description: Conflict
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    RateLimited:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key or Session Token

````