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

> ## Agent Instructions
> To set up traceroot in a repository, follow the setup prompt in https://traceroot.ai/docs/getting-started/coding-agents.md.

# Apply a production label

> Apply an existing project label to a production trace or span with a project API key. Use the same idempotency key when retrying the request.

Use a project API key. Create the label in Project Settings before applying it.


## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/public/labels
openapi: 3.1.0
info:
  title: traceroot Public API
  version: 0.1.0
servers:
  - description: traceroot Cloud
    url: https://app.traceroot.ai
  - description: Self-hosted
    url: '{baseUrl}'
    variables:
      baseUrl:
        default: http://localhost:8000
        description: Your traceroot backend URL
security: []
paths:
  /api/v1/public/labels:
    post:
      tags:
        - Labels
      summary: Apply a production label
      description: >-
        Apply a project label to a production trace or one of its spans.


        Use a project API key and the same idempotency key on retry. Retrying
        the

        same trace, span, author and value returns the original assignment ID.
      operationId: write_label
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WriteLabelRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WriteLabelResponse'
          description: Successful Response
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Invalid label request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Authentication failed
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Label target outside retention
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Project label or eligible target not found
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Idempotency key used for a different assignment
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Validation error
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Rate limit exceeded
          headers:
            Retry-After:
              description: Seconds to wait before retrying
              schema:
                type: integer
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Failed to verify label target
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Authentication service unavailable
      security:
        - BearerAuth: []
components:
  schemas:
    WriteLabelRequest:
      additionalProperties: false
      description: Apply an existing project label to a user trace or span.
      properties:
        author_id:
          description: Project-scoped ID of the end user who applied the label.
          maxLength: 128
          minLength: 1
          title: Author Id
          type: string
        idempotency_key:
          maxLength: 128
          minLength: 1
          title: Idempotency Key
          type: string
        span_id:
          anyOf:
            - maxLength: 128
              minLength: 1
              type: string
            - type: 'null'
          title: Span Id
        trace_id:
          maxLength: 128
          minLength: 1
          title: Trace Id
          type: string
        value:
          maxLength: 100
          minLength: 1
          title: Value
          type: string
      required:
        - trace_id
        - author_id
        - value
        - idempotency_key
      title: WriteLabelRequest
      type: object
    WriteLabelResponse:
      description: The saved assignment ID, also returned on retries.
      properties:
        id:
          minLength: 1
          title: Id
          type: string
      required:
        - id
      title: WriteLabelResponse
      type: object
    ErrorResponse:
      description: >-
        The canonical public error envelope (matches the gateway's normalized
        shape).
      properties:
        detail:
          title: Detail
          type: string
      required:
        - detail
      title: ErrorResponse
      type: object
  securitySchemes:
    BearerAuth:
      scheme: bearer
      type: http

````

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