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

# Create Turn Metrics

> Create a turn metrics record.

This endpoint is called by workers to persist per-turn LLM metrics
including tokens, cost, duration, and tool usage.



## OpenAPI

````yaml https://control-plane.kubiya.ai/api/openapi.json post /api/v1/analytics/turns
openapi: 3.1.0
info:
  title: Agent Control Plane API
  description: Multi-tenant agent orchestration with Temporal workflows
  version: 1.0.0
servers: []
security:
  - BearerAuth: []
tags:
  - name: health
    description: 🏥 **Health & Status** - Check API health and availability
  - name: authentication
    description: 🔐 **Authentication** - Token validation and auth management
  - name: agents
    description: 🤖 **Agents** - Create and manage AI agents with custom capabilities
  - name: skills
    description: 🛠️ **Tool Sets** - Manage agent skills and tool configurations
  - name: integrations
    description: 🔌 **Integrations** - Connect to external services (Kubiya managed)
  - name: custom-integrations
    description: >-
      ⚙️ **Custom Integrations** - User-defined integration instances with env
      vars, secrets, and files
  - name: integration-templates
    description: >-
      📦 **Integration Templates** - Pre-configured templates for common
      services (PostgreSQL, Redis, MongoDB, etc.)
  - name: secrets
    description: 🔑 **Secrets** - Secure credential storage and retrieval
  - name: teams
    description: 👥 **Teams** - Team management and collaboration
  - name: workflows
    description: 📊 **Workflows** - Multi-step automation and orchestration
  - name: executions
    description: ▶️ **Executions** - Track and monitor workflow runs
  - name: jobs
    description: ⏰ **Jobs** - Scheduled and webhook-triggered tasks
  - name: policies
    description: 🛡️ **Policies** - Access control and security policies
  - name: analytics
    description: 📈 **Analytics** - Usage metrics and performance monitoring
  - name: projects
    description: 📁 **Projects** - Project organization and management
  - name: environments
    description: 🌍 **Environments** - Environment configuration (dev, staging, prod)
  - name: models
    description: 🧠 **Models** - LLM model configuration and management
  - name: runtimes
    description: ⚡ **Runtimes** - Agent execution runtime environments
  - name: workers
    description: 👷 **Workers** - Worker registration and heartbeat monitoring
  - name: storage
    description: 💾 **Storage** - File storage and cloud integration
  - name: context-graph
    description: 🕸️ **Context Graph** - Knowledge graph and context management
  - name: temporal-workflows
    description: >-
      ⚙️ **Temporal Workflows** - Background workflows for context graph
      ingestion, connector operations, and scheduled jobs
  - name: templates
    description: 📝 **Templates** - Reusable configuration templates
paths:
  /api/v1/analytics/turns:
    post:
      summary: Create Turn Metrics
      description: |-
        Create a turn metrics record.

        This endpoint is called by workers to persist per-turn LLM metrics
        including tokens, cost, duration, and tool usage.
      operationId: create_turn_metrics_api_v1_analytics_turns_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TurnMetricsCreate'
        required: true
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    TurnMetricsCreate:
      properties:
        execution_id:
          type: string
          title: Execution Id
        turn_number:
          type: integer
          title: Turn Number
        turn_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Turn Id
        model:
          type: string
          title: Model
        model_provider:
          anyOf:
            - type: string
            - type: 'null'
          title: Model Provider
        started_at:
          type: string
          title: Started At
        completed_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Completed At
        duration_ms:
          anyOf:
            - type: integer
            - type: 'null'
          title: Duration Ms
        input_tokens:
          type: integer
          title: Input Tokens
          default: 0
        output_tokens:
          type: integer
          title: Output Tokens
          default: 0
        cache_read_tokens:
          type: integer
          title: Cache Read Tokens
          default: 0
        cache_creation_tokens:
          type: integer
          title: Cache Creation Tokens
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
        input_cost:
          type: number
          title: Input Cost
          default: 0
        output_cost:
          type: number
          title: Output Cost
          default: 0
        cache_read_cost:
          type: number
          title: Cache Read Cost
          default: 0
        cache_creation_cost:
          type: number
          title: Cache Creation Cost
          default: 0
        total_cost:
          type: number
          title: Total Cost
          default: 0
        finish_reason:
          anyOf:
            - type: string
            - type: 'null'
          title: Finish Reason
        response_preview:
          anyOf:
            - type: string
            - type: 'null'
          title: Response Preview
        tools_called_count:
          type: integer
          title: Tools Called Count
          default: 0
        tools_called_names:
          items:
            type: string
          type: array
          title: Tools Called Names
        error_message:
          anyOf:
            - type: string
            - type: 'null'
          title: Error Message
        metrics:
          additionalProperties: true
          type: object
          title: Metrics
        runtime_minutes:
          type: number
          title: Runtime Minutes
          default: 0
        model_weight:
          type: number
          title: Model Weight
          default: 1
        tool_calls_weight:
          type: number
          title: Tool Calls Weight
          default: 1
        aem_value:
          type: number
          title: Aem Value
          default: 0
        aem_cost:
          type: number
          title: Aem Cost
          default: 0
      type: object
      required:
        - execution_id
        - turn_number
        - model
        - started_at
      title: TurnMetricsCreate
      description: Schema for creating a turn metrics record
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'Enter your Kubiya API token (format: Bearer <token>)'

````