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
| Name | Type | Description |
|---|---|---|
KnowledgatorAPI-Key | String | Your API key |
Content-Type | String | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
training_id | String | Yes | Unique training job identifier (2-64 chars, alphanumeric with hyphens) |
metric | String | Yes | Metric name (currently only loss is supported) |
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
offset | Integer | No | Pagination offset (default: 0, min: 0) |
limit | Integer | No | Maximum 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 pointsstep: Training step numbervalue: Metric value at this steptimestamp: ISO 8601 timestamp when metric was recorded
total: Total number of data points for this metricoffset: Current pagination offsetlimit: Current pagination limit
Error Codes
| Status Code | Description |
|---|---|
| 200 | OK – Request successful. |
| 400 | Bad Request – Invalid input, training doesn't exist, or invalid metric. |
| 401 | Unauthorized – Invalid API key or email verification required. |
| 500 | Internal Server Error – Server-side issue. |
| 503 | Service 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
lossis 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.