This document provides comprehensive documentation for the LinX (灵枢) REST API.
Base URL: https://api.your-domain.com/api/v1
API Version: v1
Content Type: application/json
OpenAPI Specification: Available at /api/v1/docs (Swagger UI)
The API uses JWT (JSON Web Tokens) for authentication.
POST /api/v1/auth/login
Content-Type: application/json
{
"username": "user@example.com",
"password": "your_password"
}Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer",
"expires_in": 3600
}Include the access token in the Authorization header:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...POST /api/v1/auth/refresh
Content-Type: application/json
{
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}POST /api/v1/auth/logout
Authorization: Bearer {access_token}GET /api/v1/users/me
Authorization: Bearer {access_token}Response:
{
"id": "user-123",
"username": "john.doe",
"email": "john@example.com",
"role": "user",
"created_at": "2024-01-01T00:00:00Z"
}PUT /api/v1/users/me
Authorization: Bearer {access_token}
Content-Type: application/json
{
"email": "newemail@example.com",
"display_name": "John Doe"
}GET /api/v1/users/{user_id}/quotas
Authorization: Bearer {access_token}Response:
{
"max_agents": 10,
"current_agents": 5,
"max_storage_gb": 100,
"current_storage_gb": 45.2,
"max_cpu_cores": 8,
"current_cpu_cores": 3.5
}GET /api/v1/agents
Authorization: Bearer {access_token}Query Parameters:
status: Filter by status (active, idle, terminated)type: Filter by agent typelimit: Number of results (default: 50)offset: Pagination offset
Response:
{
"agents": [
{
"id": "agent-123",
"name": "Data Analyst 1",
"type": "data_analyst",
"status": "active",
"skills": ["data_processing", "sql_query"],
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-02T00:00:00Z"
}
],
"total": 5,
"limit": 50,
"offset": 0
}GET /api/v1/agents/{agent_id}
Authorization: Bearer {access_token}POST /api/v1/agents
Authorization: Bearer {access_token}
Content-Type: application/json
{
"name": "My Data Analyst",
"type": "data_analyst",
"description": "Analyzes sales data",
"skills": ["data_processing", "sql_query"],
"config": {
"cpu_limit": 2,
"memory_limit_mb": 2048
}
}Response:
{
"id": "agent-456",
"name": "My Data Analyst",
"type": "data_analyst",
"status": "idle",
"skills": ["data_processing", "sql_query"],
"created_at": "2024-01-03T00:00:00Z"
}PUT /api/v1/agents/{agent_id}
Authorization: Bearer {access_token}
Content-Type: application/json
{
"name": "Updated Name",
"description": "Updated description"
}DELETE /api/v1/agents/{agent_id}
Authorization: Bearer {access_token}GET /api/v1/agents/templates
Authorization: Bearer {access_token}Response:
{
"templates": [
{
"id": "data_analyst",
"name": "Data Analyst",
"description": "Analyzes and processes data",
"skills": ["data_processing", "sql_query", "data_visualization"],
"default_config": {
"cpu_limit": 2,
"memory_limit_mb": 2048
}
}
]
}GET /api/v1/tasks
Authorization: Bearer {access_token}Query Parameters:
status: Filter by status (pending, in_progress, completed, failed)agent_id: Filter by agentlimit: Number of resultsoffset: Pagination offset
GET /api/v1/tasks/{task_id}
Authorization: Bearer {access_token}Response:
{
"id": "task-123",
"goal": "Analyze Q4 sales data",
"status": "completed",
"agent_id": "agent-123",
"created_at": "2024-01-01T00:00:00Z",
"completed_at": "2024-01-01T01:00:00Z",
"result": {
"summary": "Q4 sales increased by 15%",
"details": {...}
}
}POST /api/v1/tasks
Authorization: Bearer {access_token}
Content-Type: application/json
{
"goal": "Analyze Q4 sales data and create a report",
"priority": "high",
"deadline": "2024-01-10T00:00:00Z"
}Response:
{
"id": "task-456",
"goal": "Analyze Q4 sales data and create a report",
"status": "pending",
"created_at": "2024-01-03T00:00:00Z"
}GET /api/v1/tasks/{task_id}/tree
Authorization: Bearer {access_token}Response:
{
"task_id": "task-123",
"goal": "Analyze Q4 sales data",
"subtasks": [
{
"task_id": "task-124",
"description": "Extract sales data from database",
"status": "completed",
"agent_id": "agent-123"
},
{
"task_id": "task-125",
"description": "Analyze trends",
"status": "in_progress",
"agent_id": "agent-124"
}
]
}POST /api/v1/tasks/{task_id}/clarify
Authorization: Bearer {access_token}
Content-Type: application/json
{
"answers": {
"question_1": "Q4 2023",
"question_2": "All regions"
}
}DELETE /api/v1/tasks/{task_id}
Authorization: Bearer {access_token}GET /api/v1/knowledge
Authorization: Bearer {access_token}Query Parameters:
type: Filter by document typetags: Filter by tags (comma-separated)limit: Number of resultsoffset: Pagination offset
GET /api/v1/knowledge/{document_id}
Authorization: Bearer {access_token}POST /api/v1/knowledge
Authorization: Bearer {access_token}
Content-Type: multipart/form-data
file: <binary>
tags: ["sales", "report"]
access_level: "internal"Response:
{
"id": "doc-123",
"filename": "sales_report.pdf",
"size_bytes": 1048576,
"type": "pdf",
"status": "processing",
"uploaded_at": "2024-01-03T00:00:00Z"
}POST /api/v1/knowledge/search
Authorization: Bearer {access_token}
Content-Type: application/json
{
"query": "sales trends 2023",
"limit": 10,
"filters": {
"type": ["pdf", "docx"],
"tags": ["sales"]
}
}Response:
{
"results": [
{
"document_id": "doc-123",
"filename": "sales_report.pdf",
"relevance_score": 0.95,
"snippet": "...sales trends in 2023 showed..."
}
],
"total": 5
}PUT /api/v1/knowledge/{document_id}
Authorization: Bearer {access_token}
Content-Type: application/json
{
"tags": ["sales", "2023", "report"],
"access_level": "confidential"
}DELETE /api/v1/knowledge/{document_id}
Authorization: Bearer {access_token}GET /api/v1/user-memory?user_id={user_id}
Authorization: Bearer {access_token}Query Parameters:
limit: Number of resultsoffset: Pagination offset
GET /api/v1/user-memory/profile?user_id={user_id}
Authorization: Bearer {access_token}GET /api/v1/skill-proposals?agent_id={agent_id}
Authorization: Bearer {access_token}POST /api/v1/skill-proposals/{memory_id}/review
Authorization: Bearer {access_token}
Content-Type: application/json
{
"action": "publish",
"note": "Proven successful path"
}GET /api/v1/skills
Authorization: Bearer {access_token}GET /api/v1/skills/{skill_id}
Authorization: Bearer {access_token}POST /api/v1/skills
Authorization: Bearer {access_token}
Content-Type: application/json
{
"name": "custom_analysis",
"description": "Custom data analysis skill",
"code": "def execute(data): ...",
"dependencies": ["pandas", "numpy"]
}const ws = new WebSocket('wss://api.your-domain.com/api/v1/ws');
// Authenticate
ws.send(JSON.stringify({
type: 'auth',
token: 'your_access_token'
}));// Subscribe to task updates
ws.send(JSON.stringify({
type: 'subscribe',
channel: 'tasks',
filters: {
user_id: 'user-123'
}
}));
// Subscribe to agent updates
ws.send(JSON.stringify({
type: 'subscribe',
channel: 'agents',
filters: {
agent_id: 'agent-123'
}
}));ws.onmessage = (event) => {
const data = JSON.parse(event.data);
switch(data.type) {
case 'task_update':
console.log('Task updated:', data.task);
break;
case 'agent_status':
console.log('Agent status:', data.status);
break;
case 'system_metric':
console.log('System metric:', data.metric);
break;
}
};task_update: Task status changedagent_status: Agent status changedsystem_metric: System metrics updatenotification: User notification
{
"error": {
"code": "INVALID_REQUEST",
"message": "Invalid request parameters",
"details": {
"field": "email",
"reason": "Invalid email format"
}
}
}200 OK: Success201 Created: Resource created400 Bad Request: Invalid request401 Unauthorized: Authentication required403 Forbidden: Insufficient permissions404 Not Found: Resource not found429 Too Many Requests: Rate limit exceeded500 Internal Server Error: Server error
INVALID_REQUEST: Invalid request parametersAUTHENTICATION_FAILED: Invalid credentialsUNAUTHORIZED: Authentication requiredFORBIDDEN: Insufficient permissionsNOT_FOUND: Resource not foundRATE_LIMIT_EXCEEDED: Too many requestsQUOTA_EXCEEDED: Resource quota exceededINTERNAL_ERROR: Server error
- Default: 100 requests per minute
- Authenticated: 1000 requests per minute
- Admin: 10000 requests per minute
Response includes rate limit headers:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 995
X-RateLimit-Reset: 1609459200When rate limit is exceeded (429 status):
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded",
"retry_after": 60
}
}Wait for retry_after seconds before retrying.
import requests
# Login
response = requests.post(
'https://api.your-domain.com/api/v1/auth/login',
json={
'username': 'user@example.com',
'password': 'password'
}
)
token = response.json()['access_token']
# Create agent
headers = {'Authorization': f'Bearer {token}'}
response = requests.post(
'https://api.your-domain.com/api/v1/agents',
headers=headers,
json={
'name': 'My Agent',
'type': 'data_analyst',
'skills': ['data_processing']
}
)
agent = response.json()
# Submit task
response = requests.post(
'https://api.your-domain.com/api/v1/tasks',
headers=headers,
json={
'goal': 'Analyze sales data'
}
)
task = response.json()// Login
const response = await fetch('https://api.your-domain.com/api/v1/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
username: 'user@example.com',
password: 'password'
})
});
const { access_token } = await response.json();
// Create agent
const agentResponse = await fetch('https://api.your-domain.com/api/v1/agents', {
method: 'POST',
headers: {
'Authorization': `Bearer ${access_token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'My Agent',
type: 'data_analyst',
skills: ['data_processing']
})
});
const agent = await agentResponse.json();# Login
curl -X POST https://api.your-domain.com/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"user@example.com","password":"password"}'
# Create agent
curl -X POST https://api.your-domain.com/api/v1/agents \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"My Agent","type":"data_analyst","skills":["data_processing"]}'Official SDKs available:
- Python:
pip install linx-sdk - JavaScript/TypeScript:
npm install @linx/sdk - Go:
go get github.com/linx/sdk-go
- API Status: https://status.your-domain.com
- Documentation: https://docs.your-domain.com
- Support: api-support@example.com
- GitHub: https://github.com/your-org/linx
See API Changelog for version history and breaking changes.