Skip to main content

Get Metrics

Retrieve training metrics for a specific training job. Currently supports loss metrics with pagination.

Endpoint​

GET https://api.platform.knowledgator.com/trainings/{training_id}/metrics/{metric}/


Headers​

NameTypeDescription
KnowledgatorAPI-KeyStringYour API key
Content-TypeStringapplication/json

Path Parameters​

ParameterTypeRequiredDescription
training_idStringYesUnique training job identifier (2-64 chars, alphanumeric with hyphens)
metricStringYesMetric name (currently only loss is supported)

Query Parameters​

ParameterTypeRequiredDescription
offsetIntegerNoPagination offset (default: 0, min: 0)
limitIntegerNoMaximum results per page (default: 100, max: 10000)

Response​

{
"metric": "loss",
"data": [
{
"step": 0,
"value": 2.456,
"timestamp": "2024-01-15T10:31:00Z"
},
{
"step": 100,
"value": 1.234,
"timestamp": "2024-01-15T10:35:00Z"
},
{
"step": 200,
"value": 0.876,
"timestamp": "2024-01-15T10:39:00Z"
}
],
"total": 3,
"offset": 0,
"limit": 100
}

Response Fields​

  • metric: Name of the metric (e.g., "loss")
  • data: Array of metric data points
    • step: Training step number
    • value: Metric value at this step
    • timestamp: ISO 8601 timestamp when metric was recorded
  • total: Total number of data points for this metric
  • offset: Current pagination offset
  • limit: Current pagination limit

Error Codes​

Status CodeDescription
200OK – Request successful.
400Bad Request – Invalid input, training doesn't exist, or invalid metric.
401Unauthorized – Invalid API key or email verification required.
500Internal Server Error – Server-side issue.
503Service Unavailable – Service temporarily unavailable.

Example Usage​

SDK Usage​

💡 Dedicated SDK Guides: See Python SDK | TypeScript SDK

TypeScript/JavaScript​

import { createClient } from '@knowledgator/typescript-sdk';

const kg = createClient('YOUR_API_KEY');

// Get loss metrics for a training job
const result = await kg.finetuning.getMetrics('78d379da228a4985ba19100f53245b79', {
metric: 'loss'
});

console.log(`Metric: ${result.metric}`);
console.log(`Total data points: ${result.total}`);

// Plot loss over time
result.data.forEach(point => {
console.log(`Step ${point.step}: ${point.value}`);
});

// Get metrics with pagination
const paginated = await kg.finetuning.getMetrics('78d379da228a4985ba19100f53245b79', {
metric: 'loss',
offset: 0,
limit: 50
});
console.log(paginated.data);

Python​

from knowledgator import Knowledgator

kg = Knowledgator(api_key="YOUR_API_KEY")

# Get loss metrics for a training job
result = kg.finetuning.get_metrics(
"78d379da228a4985ba19100f53245b79",
metric="loss"
)

print(f"Metric: {result.metric}")
print(f"Total data points: {result.total}")

# Plot loss over time
for point in result.data:
print(f"Step {point.step}: {point.value}")

# Get metrics with pagination
paginated = kg.finetuning.get_metrics(
"78d379da228a4985ba19100f53245b79",
metric="loss",
offset=0,
limit=50
)
print(paginated.data)

Expected SDK Output​

Metric: loss
Total data points: 3
Step 0: 2.456
Step 100: 1.234
Step 200: 0.876

Python​

import requests

url = "https://api.platform.knowledgator.com/trainings/78d379da228a4985ba19100f53245b79/metrics/loss/"
headers = {
"KnowledgatorAPI-Key": "YOUR_API_KEY"
}

# Get loss metrics
response = requests.get(url, headers=headers)
print(response.json())

# Get metrics with pagination
params = {
"offset": 0,
"limit": 50
}
response = requests.get(url, headers=headers, params=params)
print(response.json())

cURL​

# Get loss metrics
curl -X GET "https://api.platform.knowledgator.com/trainings/78d379da228a4985ba19100f53245b79/metrics/loss/" \
-H "KnowledgatorAPI-Key: YOUR_API_KEY"

# Get metrics with pagination
curl -X GET "https://api.platform.knowledgator.com/trainings/78d379da228a4985ba19100f53245b79/metrics/loss/?offset=0&limit=50" \
-H "KnowledgatorAPI-Key: YOUR_API_KEY"

Expected Response (cURL)​

{
"metric": "loss",
"data": [
{
"step": 0,
"value": 2.456,
"timestamp": "2024-01-15T10:31:00Z"
},
{
"step": 100,
"value": 1.234,
"timestamp": "2024-01-15T10:35:00Z"
},
{
"step": 200,
"value": 0.876,
"timestamp": "2024-01-15T10:39:00Z"
}
],
"total": 3,
"offset": 0,
"limit": 50
}

Additional Information​

  • Supported Metrics: Currently only loss is supported. Additional metrics may be added in the future
  • Data Points: Metrics are recorded at regular intervals during training
  • Pagination: Use offset and limit to retrieve large metric datasets efficiently
  • Use Cases:
    • Monitor training convergence
    • Detect overfitting or underfitting
    • Compare different training runs
    • Visualize training progress with charts
    • Determine optimal stopping points

Tip: Plot the loss metric over training steps to visualize model convergence and identify potential issues like plateaus or divergence.