API Reference¶
k13d exposes a REST API for programmatic access to Kubernetes management features.
Authentication¶
Login¶
Response:
Using Token¶
Include the token in subsequent requests:
Logout¶
Health & Status¶
Health Check¶
Response:
Kubernetes Resources¶
List Resources¶
Resources: pods, deployments, services, configmaps, secrets, nodes, etc.
Example:
Response:
{
"items": [
{
"name": "nginx-abc123",
"namespace": "default",
"status": "Running",
"ready": "1/1",
"restarts": 0,
"age": "2d"
}
],
"total": 1
}
Get Resource¶
Example:
Get YAML¶
Describe Resource¶
Delete Resource¶
Pod Operations¶
Get Logs¶
Parameters: - namespace: Pod namespace - container: Container name (optional if single container) - tail: Number of lines (default: 100) - follow: Stream logs (default: false) - previous: Previous container logs (default: false)
Example:
Execute Command¶
POST /api/pods/{name}/exec
Content-Type: application/json
{
"namespace": "default",
"container": "nginx",
"command": ["sh", "-c", "ls -la"]
}
Port Forward¶
POST /api/portforward
Content-Type: application/json
{
"namespace": "default",
"pod": "nginx-abc123",
"localPort": 8888,
"podPort": 80
}
Response:
Stop port forward:
Deployment Operations¶
Scale¶
POST /api/deployment/scale
Content-Type: application/json
{
"namespace": "default",
"name": "nginx",
"replicas": 5
}
Restart¶
POST /api/deployment/restart
Content-Type: application/json
{
"namespace": "default",
"name": "nginx"
}
Rollback¶
POST /api/deployment/rollback
Content-Type: application/json
{
"namespace": "default",
"name": "nginx",
"revision": 2
}
Node Operations¶
Cordon¶
Uncordon¶
Drain¶
POST /api/node/drain
Content-Type: application/json
{
"name": "node-1",
"ignoreDaemonSets": true,
"deleteLocalData": false,
"force": false
}
Metrics¶
Pod Metrics¶
Response:
{
"items": [
{
"name": "nginx-abc123",
"namespace": "default",
"cpu": "50m",
"memory": "128Mi"
}
]
}
Node Metrics¶
Helm¶
List Releases¶
Install Chart¶
POST /api/helm/install
Content-Type: application/json
{
"name": "my-release",
"namespace": "default",
"chart": "nginx",
"repo": "https://charts.bitnami.com/bitnami",
"values": {
"replicaCount": 3
}
}
Upgrade Release¶
POST /api/helm/upgrade
Content-Type: application/json
{
"name": "my-release",
"namespace": "default",
"chart": "nginx",
"values": {
"replicaCount": 5
}
}
Uninstall Release¶
AI Chat¶
Send Message (SSE)¶
POST /api/chat/agentic
Content-Type: application/json
{
"message": "Why is my nginx pod failing?",
"context": {
"namespace": "default",
"resource": "pod/nginx-abc123"
}
}
Response (Server-Sent Events):
event: chunk
data: {"content": "Let me check"}
event: chunk
data: {"content": " your nginx pod..."}
event: tool_request
data: {"tool": "kubectl", "command": "get pod nginx-abc123 -o yaml", "id": "tc-123"}
event: tool_execution
data: {"id": "tc-123", "result": "..."}
event: stream_end
data: {"complete": true}
Approve Tool¶
Get Chat History¶
Clear Chat¶
Audit¶
Get Audit Logs¶
Response:
{
"items": [
{
"id": 1,
"timestamp": "2024-01-15T10:30:00Z",
"user": "admin",
"action": "execute",
"resource": "pod/nginx",
"details": {
"command": "kubectl get pods"
}
}
],
"total": 100
}
Filter Audit Logs¶
Settings¶
Get Settings¶
Update Settings¶
PUT /api/settings
Content-Type: application/json
{
"language": "en",
"beginner_mode": false,
"auto_approve_readonly": true
}
Get LLM Config¶
Update LLM Config¶
PUT /api/settings/llm
Content-Type: application/json
{
"provider": "openai",
"model": "gpt-4",
"api_key": "sk-..."
}
MCP Servers¶
List MCP Servers¶
Add MCP Server¶
POST /api/mcp/servers
Content-Type: application/json
{
"name": "thinking",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-sequential-thinking"],
"enabled": true
}
Enable/Disable Server¶
Remove MCP Server¶
Reports¶
Generate Report¶
POST /api/reports
Content-Type: application/json
{
"type": "cluster-overview",
"format": "pdf",
"namespace": "default"
}
Response:
Get Report Status¶
Download Report¶
Error Responses¶
Standard Error Format¶
Common Error Codes¶
| Code | HTTP Status | Description |
|---|---|---|
UNAUTHORIZED | 401 | Invalid or missing token |
FORBIDDEN | 403 | Insufficient permissions |
NOT_FOUND | 404 | Resource not found |
VALIDATION_ERROR | 400 | Invalid request |
K8S_ERROR | 500 | Kubernetes API error |
LLM_ERROR | 500 | LLM provider error |
Rate Limiting¶
API requests are rate limited:
- Default: 100 requests/minute
- AI Chat: 10 requests/minute
Rate limit headers:
SDK Examples¶
cURL¶
# Login
TOKEN=$(curl -s -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{"password": "secret"}' | jq -r '.token')
# List pods
curl http://localhost:8080/api/k8s/pods \
-H "Authorization: Bearer $TOKEN"
# AI chat
curl -X POST http://localhost:8080/api/chat/agentic \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"message": "list pods"}'
Python¶
import requests
base_url = "http://localhost:8080"
# Login
resp = requests.post(f"{base_url}/api/auth/login",
json={"password": "secret"})
token = resp.json()["token"]
headers = {"Authorization": f"Bearer {token}"}
# List pods
pods = requests.get(f"{base_url}/api/k8s/pods", headers=headers)
print(pods.json())
JavaScript¶
const baseUrl = 'http://localhost:8080';
// Login
const loginResp = await fetch(`${baseUrl}/api/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: 'secret' })
});
const { token } = await loginResp.json();
// List pods
const podsResp = await fetch(`${baseUrl}/api/k8s/pods`, {
headers: { 'Authorization': `Bearer ${token}` }
});
const pods = await podsResp.json();
Next Steps¶
- CLI Reference - Command line options
- Environment Variables - Configuration
- Configuration - Full config guide