API Documentation and SDK
Overview
This document provides detailed API interface specifications and SDK usage examples for the SIA platform, helping developers quickly integrate and use SIA services.
API Overview
Basic Information
- Base URL:
https://api.sianexx.xyz - API Version: v1.0
- Authentication: API Key / OAuth 2.0
- Data Format: JSON
- Character Encoding: UTF-8
Authentication Mechanism
API Key Authentication
Authorization: Bearer YOUR_API_KEY
OAuth 2.0 Authentication
Authorization: Bearer YOUR_ACCESS_TOKEN
Core APIs
Agent Management API
Register Agent
POST /api/v1/agents
Request Parameters:
{
"name": "MyAgent",
"version": "1.0.0",
"capabilities": ["text_processing", "data_analysis"],
"description": "A sample agent",
"metadata": {
"author": "[email protected]",
"license": "MIT"
}
}
Response:
{
"agent_id": "agent_123456",
"status": "registered",
"created_at": "2024-01-01T00:00:00Z"
}
Deploy Agent
POST /api/v1/agents/{agent_id}/deploy
Request Parameters:
{
"resources": {
"cpu": 1,
"memory": "2GB",
"storage": "10GB"
},
"environment": {
"NODE_ENV": "production"
}
}
Task Management API
Submit Task
POST /api/v1/tasks
Request Parameters:
{
"agent_id": "agent_123456",
"task_type": "data_analysis",
"data": {
"input": "sample data"
},
"priority": "normal",
"timeout": 300
}
Query Task Status
GET /api/v1/tasks/{task_id}
Response:
{
"task_id": "task_789012",
"status": "completed",
"result": {
"processed": true,
"data": "analysis result"
},
"created_at": "2024-01-01T00:00:00Z",
"completed_at": "2024-01-01T00:01:00Z"
}
Data Management API
Upload Data
POST /api/v1/data
Request Parameters:
{
"name": "dataset_001",
"type": "training_data",
"format": "json",
"data": {...}
}
Query Data
GET /api/v1/data/{data_id}
SDK Usage
JavaScript SDK
Installation
npm install @sia/sdk
Basic Usage
import { SiaClient } from '@sia/sdk';
const client = new SiaClient({
apiKey: 'your_api_key',
endpoint: [https://api.sianexx.xyz](https://api.sianexx.xyz)
});
// Register agent
const agent = await client.registerAgent({
name: 'MyAgent',
version: '1.0.0',
capabilities: ['text_processing']
});
// Deploy agent
const deployment = await client.deployAgent(agent.agent_id, {
resources: { cpu: 1, memory: '2GB' }
});
// Submit task
const task = await client.submitTask({
agent_id: agent.agent_id,
task_type: 'data_analysis',
data: { input: 'sample data' }
});
Python SDK
Installation
pip install sia-sdk
Basic Usage
from sia_sdk import SiaClient
client = SiaClient(
api_key='your_api_key',
endpoint=[https://api.sianexx.xyz](https://api.sianexx.xyz)
)
# Register agent
agent = await client.register_agent({
'name': 'MyAgent',
'version': '1.0.0',
'capabilities': ['text_processing']
})
# Deploy agent
deployment = await client.deploy_agent(agent['agent_id'], {
'resources': {'cpu': 1, 'memory': '2GB'}
})
# Submit task
task = await client.submit_task({
'agent_id': agent['agent_id'],
'task_type': 'data_analysis',
'data': {'input': 'sample data'}
})
Java SDK
Maven Dependency
<dependency>
<groupId>com.sia</groupId>
<artifactId>sia-sdk</artifactId>
<version>1.0.0</version>
</dependency>
Basic Usage
import com.sia.SiaClient;
import com.sia.model.Agent;
import com.sia.model.Task;
SiaClient client = new SiaClient.Builder()
.apiKey("your_api_key")
.endpoint("https://api.sianexx.xyz")
.build();
// Register agent
Agent agent = client.registerAgent(Agent.builder()
.name("MyAgent")
.version("1.0.0")
.capabilities(Arrays.asList("text_processing"))
.build());
// Deploy agent
Deployment deployment = client.deployAgent(agent.getAgentId(),
DeploymentConfig.builder()
.cpu(1)
.memory("2GB")
.build());
// Submit task
Task task = client.submitTask(Task.builder()
.agentId(agent.getAgentId())
.taskType("data_analysis")
.data(Map.of("input", "sample data"))
.build());
Error Handling
Error Codes
| Error Code | Description | Solution |
|---|---|---|
| 400 | Invalid request parameters | Check request parameter format |
| 401 | Authentication failed | Check API Key or Token |
| 403 | Insufficient permissions | Check account permissions |
| 404 | Resource not found | Check resource ID |
| 429 | Rate limit exceeded | Reduce request frequency |
| 500 | Internal server error | Contact technical support |
Error Response Format
{
"error": {
"code": 400,
"message": "Invalid request parameters",
"details": {
"field": "name",
"issue": "Required field missing"
}
}
}
Best Practices
Performance Optimization
Batch Operations
- Use batch APIs to reduce request count
- Set appropriate batch sizes
- Process large batches asynchronously
Caching Strategy
- Cache frequently accessed data
- Use ETag for conditional requests
- Implement local caching mechanisms
Security Considerations
API Key Management
- Rotate API keys regularly
- Use principle of least privilege
- Monitor API key usage
Data Security
- Encrypt sensitive data
- Use HTTPS for transmission
- Implement request signature verification
Monitoring and Debugging
Logging
- Log all API calls
- Monitor response times
- Track error rates
Debugging Tools
- Use API debugging tools
- Enable detailed logging
- Monitor network traffic
Example Projects
Complete Example
Agent Development Example
// Complete agent development example
import { SiaClient, Agent } from '@sia/sdk';
class MyAgent extends Agent {
constructor() {
super({
name: 'MyAgent',
version: '1.0.0',
capabilities: ['text_processing', 'data_analysis']
});
}
async processTask(task) {
// Task processing logic
const result = await this.analyzeData(task.data);
return {
task_id: task.id,
status: 'completed',
data: result
};
}
async analyzeData(data) {
// Data analysis logic
return {
processed: true,
result: 'Analysis completed'
};
}
}
// Usage example
async function main() {
const client = new SiaClient({
apiKey: process.env.SIA_API_KEY
});
const agent = new MyAgent();
const registration = await client.registerAgent(agent);
console.log('Agent registered:', registration.agent_id);
}
For more development details, please refer to Community Support