The system endpoints provide information about the Sudo API status and available models. These are typically used for health monitoring and discovering available AI models.
Health Check
Check if the Sudo API and backend infrastructure are healthy and ready to accept connections.
Basic Usage
import { Sudo } from "sudo-ai";
const sudo = new Sudo({
serverURL: "https://sudoapp.dev/api",
apiKey: process.env.SUDO_API_KEY ?? "",
});
async function checkHealth() {
try {
// Check API health
const healthStatus = await sudo.system.healthCheck();
console.log(`API Status: ${JSON.stringify(healthStatus)}`);
} catch (error) {
console.error("Health check failed:", error);
}
}
checkHealth();
Python Async Usage
import asyncio
import os
from sudo import Sudo
async def check_health():
async with Sudo(
server_url="https://sudoapp.dev/api",
api_key=os.getenv("SUDO_API_KEY"),
) as client:
health_status = await client.system.health_check_async()
return health_status
# Run the async function
health = asyncio.run(check_health())
print(f"API Status: {health}")
Get Supported Models
Retrieve a list of all AI models supported by the Sudo API, including their capabilities and pricing information.
Basic Usage
import { Sudo } from "sudo-ai";
const sudo = new Sudo({
serverURL: "https://sudoapp.dev/api",
apiKey: process.env.SUDO_API_KEY,
});
async function getSupportedModels() {
try {
const models = await sudo.system.getSupportedModels();
console.log(`Available models: ${models.data.length}`);
models.data.forEach(m => {
console.log(`- ${m.modelName} (${m.modelProvider})`);
});
} catch (error) {
console.error("Failed to get models:", error);
}
}
getSupportedModels();
Python Async Usage
import asyncio
import os
from sudo import Sudo
async def get_models_info():
async with Sudo(
server_url="https://sudoapp.dev/api",
api_key=os.getenv("SUDO_API_KEY"),
) as client:
models = await client.system.get_supported_models_async()
return models
# Get models asynchronously
models = asyncio.run(get_models_info())
print(f"Found {len(models.data)} models")
Error Handling
Both system endpoints can encounter various errors. Here’s how to handle them:
import { Sudo } from "sudo-ai";
import * as errors from "sudo-ai/models/errors";
const sudo = new Sudo({
serverURL: "https://sudoapp.dev/api",
apiKey: process.env.SUDO_API_KEY ?? "",
});
async function systemEndpointsWithErrorHandling() {
try {
// Try health check
const health = await sudo.system.healthCheck();
console.log("✅ Health check passed");
// Try getting models
const models = await sudo.system.getSupportedModels();
console.log(`✅ Retrieved ${models.data.length} models`);
} catch (error) {
if (error instanceof errors.SudoError) {
if (error.statusCode === 401) {
console.log("❌ Authentication failed - check your API key");
} else if (error.statusCode >= 500) {
console.log("❌ Server error - the API may be experiencing issues");
} else {
console.log(`❌ API error: ${error.message}`);
console.log(`Status: ${error.statusCode}`);
}
if (error instanceof errors.ErrorResponse) {
console.log(`Error details: ${error.data$.error}`);
}
} else {
console.log(`❌ Unexpected error: ${error}`);
}
}
}
systemEndpointsWithErrorHandling();
Next Steps
Now that you understand the system endpoints:
- Try AI Responses - Start creating AI responses
- Explore Streaming - Add real-time capabilities
- Advanced Features - Function calling and more
Use the health check endpoint in your application’s readiness probes and the models endpoint to dynamically discover available AI models. Both TypeScript and Python SDKs provide the same system information with language-appropriate handling.