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

# Append trials to an open coding-agent run

> Adds finished trials to a run opened with `finalize: false`, so a job started from MKA1 can be watched while it runs instead of appearing complete out of nowhere at the end. Each trial pins its own `sample_index` and upserts on (task, model, sample_index): a harness cannot tell a timeout from a lost response, so re-sending a batch is safe and replaces rather than duplicates. The whole batch and its aggregate recompute land in one transaction, serialized per run. Counts, metrics and cost are recomputed from the stored rows on every call, never accumulated from the request, so a replayed batch cannot double them. Send `finalize: true` (usually with an empty `trials`) to close the run — until then it stays `in_progress` and off the leaderboards, which only count completed runs. Appending to an already-completed or cancelled run is rejected: that record is finished, and rewriting it would silently move a number someone may have already read.



## OpenAPI

````yaml https://apigw.mka1.com/speakeasy.json post /api/v1/llm/evals/runs/{run_id}/trials
openapi: 3.1.1
info:
  title: MKA1 API
  version: 1.1.0
  description: >-
    The MKA1 API is a RESTful API that provides access to the MKA1 platform.
    Learn how to get started with the API and the TypeScript SDK
    [here](https://mka1.apidocumentation.com/guides/getting-started).
  license:
    name: Proprietary
servers:
  - url: https://apigw.mka1.com
    description: MKA1 API Gateway
  - url: /
    description: Relative server URL (configurable via SDK constructor)
security: []
tags:
  - name: Resource Authorization
    description: >-
      Manage permissions for LLM resources. Create resources, grant/revoke
      permissions, and delete resources. Only resource owners can grant, revoke,
      or delete permissions.
    x-displayName: Resource Authorization
  - name: Embeddings
    description: >-
      Text embedding API endpoints for generating vector representations of
      text. Create semantic embeddings for search, clustering, and similarity
      matching using various embedding models.
    x-displayName: Embeddings
  - name: Feedback
    description: >-
      User feedback API for rating and commenting on chat completions. Collect
      thumbs up/down ratings and detailed feedback to improve model responses
      and track user satisfaction.
    x-displayName: Feedback
  - name: Images
    description: >-
      Image generation API endpoints for creating images from text descriptions.
      Generate images with control over size, quality, and style.
    x-displayName: Images
  - name: MCP Vault
    description: >-
      MCP vault API for storing user-owned MCP server configurations and
      encrypted credentials. Agents reference vault IDs so secrets are resolved
      only at tool execution time.
    x-displayName: MCP Vault
  - name: Speech
    description: >-
      Speech API endpoints for audio processing. Convert text to
      natural-sounding speech (TTS) or transcribe speech to text (STT) in
      different languages.
    x-displayName: Speech
  - name: Usage
    description: >-
      Usage tracking and analytics API for monitoring token consumption, request
      counts, and cost analysis. View detailed statistics per user, model, and
      time period.
    x-displayName: Usage
  - name: Extract
    description: >-
      Structured data extraction API for extracting information from files.
      Define JSON schemas to extract structured data from images, PDFs, and
      documents. Supports reusable schema templates.
    x-displayName: Extract
  - name: Text Classification
    description: >-
      Text classification API for categorizing text into predefined labels. Use
      AI models to classify text content for sentiment analysis, topic
      categorization, and content moderation.
    x-displayName: Text Classification
  - name: Responses
    description: >-
      Agent-powered responses API for creating AI agents with autonomous tool
      usage. Build conversational assistants that can use web search, file
      operations, image generation, code execution, computer use simulation, and
      MCP integrations. Supports background processing, streaming, and real-time
      status tracking.
    x-displayName: Responses
  - name: Files
    description: >-
      File management API for uploading, storing, and managing files with
      automatic expiration and S3 integration. Upload files that can be used
      with Assistants, Vector Stores, and other features. Files are stored in S3
      with metadata tracked in PostgreSQL. Supports automatic cleanup of expired
      files.
    x-displayName: Files
  - name: Vector Stores
    description: >-
      Vector store API for storing and searching documents using embeddings.
      Create vector stores, upload files with automatic chunking and embedding
      generation, and perform semantic search. Files are processed
      asynchronously using Temporal workflows for durability. Supports automatic
      cleanup of expired stores and LanceDB for efficient vector storage.
    x-displayName: Vector Stores
  - name: Conversations
    description: >-
      Conversation management API for storing and retrieving conversation state
      across Response API calls. Create conversations, add items (user messages,
      assistant messages, system messages), and maintain conversation history.
      Supports metadata tracking and multi-turn dialogue state management.
    x-displayName: Conversations
  - name: Guardrails
    description: >-
      AI safety guardrails API for configuring content moderation and security
      policies. Set up ban word lists, prompt injection detection, and system
      prompt leakage prevention. Guardrails apply to all requests from an
      account and can be tested before deployment.
    x-displayName: Guardrails
  - name: Models
    description: >-
      Model listing API for discovering available models. Returns model IDs,
      ownership, and metadata for all registered models in the gateway.
    x-displayName: Models
  - name: Skills
    description: >-
      Skills API for managing versioned bundles of instructions and files
      following the Agent Skills standard. Create, version, and download
      reusable skill packages that include SKILL.md manifests for agent
      environments.
    x-displayName: Skills
  - name: Chat Completions
    description: >-
      **Deprecated: Use the Responses API (`/api/v1/llm/responses`) instead.**
      Chat completion endpoints with support for streaming, tool calls, and
      multiple providers.
    x-deprecated: true
    x-displayName: Chat Completions
  - name: Batches
    x-displayName: Batches
  - name: Evals
    x-displayName: Evals
  - name: Fine-Tuning
    x-displayName: Fine-Tuning
  - name: Memory Stores
    x-displayName: Memory Stores
  - name: Prompts
    x-displayName: Prompts
  - name: API Key
    x-displayName: API Key
  - name: Session
    x-displayName: Session
  - name: Organization
    x-displayName: Organization
  - name: Cluster Admin
    x-displayName: Cluster Admin
  - name: Sessions
    description: Create, inspect, access, and terminate sandbox sessions.
    x-displayName: Sessions
  - name: Browser
    description: >-
      Connect to browser sessions through the gateway port proxy. Browser
      sessions expose a Chrome DevTools Protocol endpoint on port 9222.
    x-displayName: Browser
  - name: Execution
    description: Run shell commands and code inside an existing sandbox session.
    x-displayName: Execution
  - name: Workspace
    description: >-
      Inspect the workspace manifest, transfer files or archives, and download
      generated artifacts.
    x-displayName: Workspace
  - name: Sandbox Usage
    description: >-
      Aggregate sandbox usage statistics across sessions, execution, and
      workspace operations.
    x-displayName: Sandbox Usage
  - name: Sandbox Pricing
    description: >-
      Cluster-admin management of the sandbox compute rate card used for
      budgeted spend.
    x-displayName: Sandbox Pricing
  - name: schema-3_other
    x-displayName: other
  - name: Agents
    description: Create and manage reusable agent definitions.
    x-displayName: Agents
  - name: Agent Versions
    description: Inspect an agent's configuration history and roll back to a prior version.
    x-displayName: Agent Versions
  - name: Agent Runs
    description: Execute saved agents and inspect persisted run results.
    x-displayName: Agent Runs
  - name: Agent Connectors
    description: >-
      Connect saved agents to external messaging channels such as Telegram,
      including text, photo, and supported document exchange.
    x-displayName: Agent Connectors
  - name: Agent Schedules
    description: Create and manage scheduled or recurring saved agent runs.
    x-displayName: Agent Schedules
  - name: schema-4_other
    x-displayName: other
  - name: Budgets
    x-displayName: Budgets
  - name: Settings
    x-displayName: Settings
  - name: Compute Jobs
    x-displayName: Compute Jobs
  - name: Compute Services
    x-displayName: Compute Services
  - name: Compute Catalog
    x-displayName: Compute Catalog
  - name: Compute Volumes
    x-displayName: Compute Volumes
  - name: Compute Pricing
    x-displayName: Compute Pricing
  - name: Compute Secrets
    x-displayName: Compute Secrets
  - name: Compute Usage
    x-displayName: Compute Usage
  - name: Compute Tenants
    x-displayName: Compute Tenants
  - description: Create, list, read, update, and delete repositories.
    name: Repositories
    x-displayName: Repositories
paths:
  /api/v1/llm/evals/runs/{run_id}/trials:
    post:
      tags:
        - Evals
      summary: Append trials to an open coding-agent run
      description: >-
        Adds finished trials to a run opened with `finalize: false`, so a job
        started from MKA1 can be watched while it runs instead of appearing
        complete out of nowhere at the end. Each trial pins its own
        `sample_index` and upserts on (task, model, sample_index): a harness
        cannot tell a timeout from a lost response, so re-sending a batch is
        safe and replaces rather than duplicates. The whole batch and its
        aggregate recompute land in one transaction, serialized per run. Counts,
        metrics and cost are recomputed from the stored rows on every call,
        never accumulated from the request, so a replayed batch cannot double
        them. Send `finalize: true` (usually with an empty `trials`) to close
        the run — until then it stays `in_progress` and off the leaderboards,
        which only count completed runs. Appending to an already-completed or
        cancelled run is rejected: that record is finished, and rewriting it
        would silently move a number someone may have already read.
      operationId: appendAgentEvalTrials
      parameters:
        - name: run_id
          in: path
          required: true
          schema:
            type: string
          example: eval_run_aa87e2b1112a455b8deabed784372198
        - name: X-On-Behalf-Of
          in: header
          required: false
          schema:
            type: string
          description: Optional external end-user identifier forwarded by the API gateway.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AppendAgentTrialsRequest'
            example:
              trials:
                - task_id: fix-permissions
                  sample_index: 0
                  status: completed
                  prompt: >-
                    The test suite fails because the fixture directory is not
                    writable. Fix it.
                  target: all tests pass
                  output_text: 9 passed in 2.25s
                  scores:
                    reward: 1
                    resolved: 1
                  cost_usd: 0.0279
                  input_tokens: 658456
                  output_tokens: 6489
                  cached_tokens: 658366
              finalize: false
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  object:
                    const: eval.run
                  suite_id:
                    type: string
                  suite_version:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  suite_version_id:
                    type: string
                  org_id:
                    type: string
                    description: The org that owns this run.
                  team_id:
                    type: string
                    description: The team that owns this run.
                  status:
                    $ref: '#/components/schemas/EvalRunStatus'
                  models:
                    type: array
                    items:
                      type: string
                  task_ids:
                    anyOf:
                      - type: array
                        items:
                          type: string
                      - type: 'null'
                  judge_model:
                    anyOf:
                      - type: string
                      - type: 'null'
                  embedding_model:
                    anyOf:
                      - type: string
                      - type: 'null'
                  generation:
                    type: object
                    properties:
                      instructions:
                        type: string
                      temperature:
                        type: number
                        minimum: 0
                        maximum: 2
                      top_p:
                        type: number
                        minimum: 0
                        maximum: 1
                      max_output_tokens:
                        type: integer
                        minimum: 1
                        maximum: 9007199254740991
                      max_gen_toks:
                        type: integer
                        minimum: 1
                        maximum: 9007199254740991
                        description: lm-eval alias for max_output_tokens.
                      stop:
                        anyOf:
                          - type: string
                          - type: array
                            minItems: 1
                            items:
                              type: string
                      until:
                        type: array
                        minItems: 1
                        items:
                          type: string
                        description: lm-eval generate_until stop sequences.
                      max_tool_calls:
                        type: integer
                        minimum: 1
                        maximum: 9007199254740991
                      reasoning: {}
                      text: {}
                      tools:
                        type: array
                        items:
                          anyOf:
                            - {}
                            - type: 'null'
                      tool_choice: {}
                      parallel_tool_calls:
                        type: boolean
                      truncation:
                        enum:
                          - auto
                          - disabled
                        type: string
                      service_tier:
                        enum:
                          - auto
                          - default
                          - flex
                          - priority
                        type: string
                      presence_penalty:
                        type: number
                        minimum: -2
                        maximum: 2
                      frequency_penalty:
                        type: number
                        minimum: -2
                        maximum: 2
                      top_k:
                        type: integer
                        minimum: 0
                        maximum: 9007199254740991
                      min_p:
                        type: number
                        minimum: 0
                        maximum: 1
                      repetition_penalty:
                        type: number
                        minimum: 0
                      do_sample:
                        type: boolean
                      extra_body:
                        type: object
                        propertyNames:
                          type: string
                        additionalProperties: {}
                      chat_template_kwargs:
                        type: object
                        propertyNames:
                          type: string
                        additionalProperties: {}
                      prefill_think:
                        anyOf:
                          - type: boolean
                          - type: string
                      use_cache:
                        type: boolean
                      timeout_seconds:
                        type: integer
                        minimum: 1
                        maximum: 3600
                      max_retries:
                        type: integer
                        minimum: 0
                        maximum: 10
                      max_empty_retries:
                        type: integer
                        minimum: 0
                        maximum: 10
                    additionalProperties: {}
                  request_counts:
                    type: object
                    properties:
                      total:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                      completed:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                      failed:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                    required:
                      - total
                      - completed
                      - failed
                  metrics:
                    anyOf:
                      - type: object
                        propertyNames:
                          type: string
                        additionalProperties: {}
                      - type: 'null'
                  error:
                    anyOf:
                      - type: object
                        propertyNames:
                          type: string
                        additionalProperties: {}
                      - type: 'null'
                  artifact_file_ids:
                    type: array
                    items:
                      type: string
                  metadata:
                    type: object
                    propertyNames:
                      type: string
                      maxLength: 64
                    additionalProperties:
                      type: string
                      maxLength: 512
                  agent_name:
                    anyOf:
                      - type: string
                      - type: 'null'
                    description: >-
                      Coding-agent harness that produced this run (e.g. `omp`,
                      `claude-code`). Null for every non-harness eval kind — a
                      null here is not a missing value, it means the run is not
                      an agent run.
                  agent_version:
                    anyOf:
                      - type: string
                      - type: 'null'
                    description: >-
                      Version of `agent_name`, as the harness reported it. Null
                      when `agent_name` is.
                  agent_effort:
                    anyOf:
                      - type: string
                      - type: 'null'
                    description: >-
                      Reasoning-effort setting the agent ran at (e.g. `medium`,
                      `xhigh`). Part of the leaderboard's row identity: the same
                      agent and model at two efforts are two rows, not one. Null
                      when `agent_name` is.
                  cost_usd:
                    anyOf:
                      - type: number
                      - type: 'null'
                    description: >-
                      Total spend for the run in USD. Null when the harness did
                      not report cost.
                  created_at:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  started_at:
                    anyOf:
                      - type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                      - type: 'null'
                  completed_at:
                    anyOf:
                      - type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                      - type: 'null'
                  cancelled_at:
                    anyOf:
                      - type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                      - type: 'null'
                  failed_at:
                    anyOf:
                      - type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                      - type: 'null'
                required:
                  - id
                  - object
                  - suite_id
                  - suite_version
                  - suite_version_id
                  - org_id
                  - team_id
                  - status
                  - models
                  - task_ids
                  - judge_model
                  - embedding_model
                  - generation
                  - request_counts
                  - metrics
                  - error
                  - artifact_file_ids
                  - metadata
                  - agent_name
                  - agent_version
                  - agent_effort
                  - cost_usd
                  - created_at
                  - started_at
                  - completed_at
                  - cancelled_at
                  - failed_at
              example:
                id: eval_run_aa87e2b1112a455b8deabed784372198
                object: eval.run
                suite_id: eval_suite_aa87e2b1112a455b8deabed784372198
                suite_version: 1
                suite_version_id: eval_sver_aa87e2b1112a455b8deabed784372198
                org_id: org-acme
                team_id: team-research
                status: in_progress
                models:
                  - auto
                task_ids: null
                judge_model: auto
                embedding_model: auto
                generation:
                  temperature: 0
                  max_output_tokens: 512
                request_counts:
                  total: 100
                  completed: 10
                  failed: 0
                metrics: null
                error: null
                artifact_file_ids: []
                metadata:
                  purpose: mvp
                agent_name: omp
                agent_version: null
                agent_effort: null
                cost_usd: null
                created_at: 1704067200
                started_at: 1704067210
                completed_at: null
                cancelled_at: null
                failed_at: null
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: python
          label: Python (SDK)
          source: |-
            from meetkai_mka1 import SDK


            with SDK(
                bearer_auth="<YOUR_BEARER_TOKEN_HERE>",
            ) as sdk:

                res = sdk.llm.evals.append_agent_trials(run_id="eval_run_aa87e2b1112a455b8deabed784372198", trials=[
                    {
                        "task_id": "fix-permissions",
                        "sample_index": 0,
                        "prompt": "The test suite fails because the fixture directory is not writable. Fix it.",
                        "target": "all tests pass",
                        "output_text": "9 passed in 2.25s",
                        "scores": {
                            "reward": 1,
                            "resolved": 1,
                        },
                        "cost_usd": 0.0279,
                        "input_tokens": 658456,
                        "output_tokens": 6489,
                        "cached_tokens": 658366,
                    },
                ], finalize=False)

                # Handle response
                print(res)
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { SDK } from "@meetkai/mka1";

            const sdk = new SDK({
              bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
            });

            async function run() {
              const result = await sdk.llm.evals.appendAgentTrials({
                runId: "eval_run_aa87e2b1112a455b8deabed784372198",
                appendAgentTrialsRequest: {
                  trials: [
                    {
                      taskId: "fix-permissions",
                      sampleIndex: 0,
                      prompt: "The test suite fails because the fixture directory is not writable. Fix it.",
                      target: "all tests pass",
                      outputText: "9 passed in 2.25s",
                      scores: {
                        "reward": 1,
                        "resolved": 1,
                      },
                      costUsd: 0.0279,
                      inputTokens: 658456,
                      outputTokens: 6489,
                      cachedTokens: 658366,
                    },
                  ],
                },
              });

              console.log(result);
            }

            run();
        - lang: csharp
          label: CSharp (SDK)
          source: |-
            using MeetKai.MKA1;
            using MeetKai.MKA1.Types.Components;
            using System.Collections.Generic;

            var sdk = new SDK(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");

            var res = await sdk.Llm.Evals.AppendAgentTrialsAsync(
                runId: "eval_run_aa87e2b1112a455b8deabed784372198",
                body: new AppendAgentTrialsRequest() {
                    Trials = new List<AppendAgentTrialsRequestTrial>() {
                        new AppendAgentTrialsRequestTrial() {
                            TaskId = "fix-permissions",
                            SampleIndex = 0,
                            Prompt = "The test suite fails because the fixture directory is not writable. Fix it.",
                            Target = "all tests pass",
                            OutputText = "9 passed in 2.25s",
                            Scores = new Dictionary<string, double>() {
                                { "reward", 1D },
                                { "resolved", 1D },
                            },
                            CostUsd = 0.0279D,
                            InputTokens = 658456,
                            OutputTokens = 6489,
                            CachedTokens = 658366,
                        },
                    },
                }
            );

            // handle response
components:
  schemas:
    AppendAgentTrialsRequest:
      type: object
      properties:
        trials:
          type: array
          maxItems: 1000
          items:
            type: object
            properties:
              task_id:
                type: string
                minLength: 1
                maxLength: 255
                description: >-
                  Must already exist in the target suite version's manifest;
                  unknown ids are rejected rather than invented.
              sample_index:
                type: integer
                minimum: 0
                maximum: 2147483647
              status:
                enum:
                  - completed
                  - failed
                type: string
                default: completed
                description: >-
                  `failed` means no score was produced at all. An agent timeout
                  is NOT that — the harness still runs the verifier and scores
                  the trial, so it stays `completed` and carries its exception
                  in `error`.
              prompt:
                type: string
                default: ''
                description: The task instruction.
              target:
                anyOf:
                  - type: string
                  - type: 'null'
              output_text:
                anyOf:
                  - type: string
                  - type: 'null'
                description: >-
                  What decided the score — the verifier's output. The agent's
                  session goes to the trajectory route.
              scores:
                type: object
                propertyNames:
                  type: string
                additionalProperties:
                  type: number
                default: {}
                description: >-
                  Metric values for this trial, e.g. `{ "reward": 1, "resolved":
                  1 }`. The board averages `reward` by default.
              error:
                anyOf:
                  - type: object
                    propertyNames:
                      type: string
                    additionalProperties: {}
                  - type: 'null'
                description: >-
                  The exception this trial recorded, if any. Does not by itself
                  make the trial a failure.
              cost_usd:
                anyOf:
                  - type: number
                    minimum: 0
                  - type: 'null'
              input_tokens:
                anyOf:
                  - type: integer
                    minimum: 0
                    maximum: 9007199254740991
                  - type: 'null'
              output_tokens:
                anyOf:
                  - type: integer
                    minimum: 0
                    maximum: 9007199254740991
                  - type: 'null'
              cached_tokens:
                anyOf:
                  - type: integer
                    minimum: 0
                    maximum: 9007199254740991
                  - type: 'null'
                description: >-
                  The share of `input_tokens` served from the provider's prompt
                  cache.
              phase_timings:
                anyOf:
                  - type: object
                    propertyNames:
                      type: string
                    additionalProperties: {}
                  - type: 'null'
            required:
              - task_id
              - sample_index
          default: []
          description: >-
            Each trial pins its own `sample_index` (unique per task and model):
            re-sending a batch replaces the same rows instead of duplicating
            them, so a retried batch is safe.
        finalize:
          type: boolean
          default: false
          description: >-
            Marks the run completed once these trials land — the last call of a
            streaming job sends this, usually with an empty `trials`.
    EvalRunStatus:
      enum:
        - queued
        - in_progress
        - finalizing
        - completed
        - failed
        - cancelling
        - cancelled
      type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Gateway auth: send `Authorization: Bearer <mka1-api-key>`. For
        multi-user server-side integrations, you can also send `X-On-Behalf-Of:
        <external-user-id>`.

````