Skip to content
POST/api/v1/agent-runs/{runId}/end

Close an agent run + roll cost into the key meter

Closes an agent run via the `agent_run_end` RPC: adds costUsd/tokensIn/tokensOut to the run row, sets status and ended_at, and shallow-merges metadata. Idempotent — a run whose status is no longer `in_progress` is returned unchanged. Cost accumulates on the `agent_runs` row only; it does NOT increment the api_key monthly meter (`api_keys.current_period_spent_usd`), which is written by the gateway's separate `api_key_record_spend` path. Body fields are all optional: costUsd/tokensIn/tokensOut default to 0, status defaults to 'completed' (enum completed|failed|budget_exceeded), metadata has no default. Requires evals:create; caller must be a member of the run's org (404 for an unknown runId). Returns { runId, costUsd, status, endedAt }.

Authentication

Send Authorization: Bearer YOUR_API_KEY on every request. Generate API keys at /dashboard/settings/api-keys.

Parameters

runId in pathrequired
string

Request body

Example

{
  "costUsd": 0,
  "tokensIn": 0,
  "tokensOut": 0,
  "status": "completed",
  "metadata": {}
}
Schema
{
  "application/json": {
    "schema": {
      "type": "object",
      "properties": {
        "costUsd": {
          "type": "number",
          "minimum": 0,
          "maximum": 1000000,
          "default": 0
        },
        "tokensIn": {
          "type": "integer",
          "minimum": 0,
          "default": 0
        },
        "tokensOut": {
          "type": "integer",
          "minimum": 0,
          "default": 0
        },
        "status": {
          "type": "string",
          "enum": [
            "completed",
            "failed",
            "budget_exceeded"
          ],
          "default": "completed"
        },
        "metadata": {
          "type": "object",
          "additionalProperties": true
        }
      }
    }
  }
}

Response

200 example

{
  "runId": "00000000-0000-0000-0000-000000000000",
  "costUsd": 0,
  "status": "string",
  "endedAt": "2026-01-01T00:00:00.000Z"
}

All status codes

200Run closed.
400(no description)
401(no description)
403Forbidden — the credential is valid but lacks the API-key scope, member role, or plan entitlement this operation requires.
404(no description)
429(no description)
500Internal Server Error — DB_ERROR.
503Service Unavailable — AUTHZ_UNAVAILABLE.

Code samples

cURL

# {runId} is shown with an EXAMPLE value — replace it with real values.
curl -X POST \
  https://evalguard.ai/api/v1/agent-runs/00000000-0000-0000-0000-000000000000/end \
  -H "Authorization: Bearer $EVALGUARD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "costUsd": 0, "tokensIn": 0, "tokensOut": 0, "status": "completed", "metadata": {} }'

TypeScript

// The TypeScript SDK (@evalguard/sdk) exposes TYPED methods — runEval,
// getEval, runSecurityScan, checkFirewall, … — not a generic request().
// For an arbitrary endpoint, call it directly:
// {runId} is shown with an EXAMPLE value — replace it with real values.

const res = await fetch("https://evalguard.ai/api/v1/agent-runs/00000000-0000-0000-0000-000000000000/end", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.EVALGUARD_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "costUsd": 0,
    "tokensIn": 0,
    "tokensOut": 0,
    "status": "completed",
    "metadata": {}
  }),
});
console.log(res.status, await res.json());

Python

# The Python SDK (pip install evalguardai) exposes TYPED methods on
# EvalGuardClient — run_eval, get_eval, … — not a generic request().
# For an arbitrary endpoint, call it directly:
# {runId} is shown with an EXAMPLE value — replace it with real values.

import os
import requests

headers = {"Authorization": f"Bearer {os.environ['EVALGUARD_API_KEY']}"}
headers["Content-Type"] = "application/json"

response = requests.request(
    "POST",
    "https://evalguard.ai/api/v1/agent-runs/00000000-0000-0000-0000-000000000000/end",
    headers=headers,
    json={
    "costUsd": 0,
    "tokensIn": 0,
    "tokensOut": 0,
    "status": "completed",
    "metadata": {}
},
)
print(response.status_code, response.json())

Go

package main

import (
	"context"
	"fmt"
	"net/http"
	"os"
	"strings"
)

// {runId} is shown with an EXAMPLE value — replace it with real values.
func main() {
	body := strings.NewReader(`{"costUsd":0,"tokensIn":0,"tokensOut":0,"status":"completed","metadata":{}}`)
	req, _ := http.NewRequestWithContext(context.Background(), "POST", "https://evalguard.ai/api/v1/agent-runs/00000000-0000-0000-0000-000000000000/end", body)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("EVALGUARD_API_KEY"))
	req.Header.Set("Content-Type", "application/json")
	resp, err := http.DefaultClient.Do(req)
	if err != nil { panic(err) }
	defer resp.Body.Close()
	fmt.Println(resp.Status)
}

Errors

400401403404429500503

Other Evals endpoints