Installation
The Sudo SDK is available for both Python and TypeScript/JavaScript. Choose your preferred language and package manager below.
npm
pnpm
yarn
bun
pip
poetry
uv
Python : Requires Python 3.9 or later
TypeScript/JavaScript : Requires Node.js 14+ and supports both CommonJS and ES Modules
Authentication
The SDK uses API key authentication. You can obtain your API key from the Sudo Developer Portal .
Environment Variable (Recommended)
Set your API key as an environment variable:
import { Sudo } from "sudo-ai" ;
const sudo = new Sudo ({
serverURL: "https://sudoapp.dev/api" ,
apiKey: process . env . SUDO_API_KEY ?? "" ,
});
// Your code here
Direct Configuration
Alternatively, you can pass the API key directly:
import { Sudo } from "sudo-ai" ;
const sudo = new Sudo ({
serverURL: "https://sudoapp.dev/api" ,
apiKey: "your-api-key-here" ,
});
// Your code here
Never hardcode your API key in your source code, especially in code that will be committed to version control. Always use environment variables or secure configuration management.
Basic Configuration
Server URL
By default, the SDK points to the production Sudo API. You can customize this:
import { Sudo } from "sudo-ai" ;
// Production (default)
const sudo = new Sudo ({
serverURL: "https://sudoapp.dev/api" ,
apiKey: "your-api-key"
});
// Custom endpoint
const customSudo = new Sudo ({
serverURL: "https://your-custom-endpoint.com/api" ,
apiKey: "your-api-key"
});
Retry Configuration
Configure retry behavior for failed requests:
import { Sudo } from "sudo-ai" ;
const sudo = new Sudo ({
serverURL: "https://sudoapp.dev/api" ,
apiKey: "your-api-key" ,
retryConfig: {
strategy: "backoff" ,
backoff: {
initialInterval: 1 ,
maxInterval: 50 ,
exponent: 1.1 ,
maxElapsedTime: 100
},
retryConnectionErrors: false
}
});
// Client will use custom retry configuration
Custom HTTP Client
For advanced use cases, you can provide a custom HTTP client:
import { Sudo } from "sudo-ai" ;
import { HTTPClient } from "sudo-ai/lib/http" ;
const httpClient = new HTTPClient ({
fetcher : ( request ) => {
return fetch ( request );
}
});
httpClient . addHook ( "beforeRequest" , ( request ) => {
const nextRequest = new Request ( request , {
signal: request . signal || AbortSignal . timeout ( 5000 )
});
nextRequest . headers . set ( "x-custom-header" , "value" );
return nextRequest ;
});
const sudo = new Sudo ({
serverURL: "https://sudoapp.dev/api" ,
apiKey: "your-api-key" ,
httpClient
});
Async Support
Both SDKs support asynchronous operations:
Async/Await
import { Sudo } from "sudo-ai" ;
const sudo = new Sudo ({
serverURL: "https://sudoapp.dev/api" ,
apiKey: process . env . SUDO_API_KEY ?? "" ,
});
async function main () {
try {
const result = await sudo . system . healthCheck ();
console . log ( result );
} catch ( error ) {
console . error ( "Error:" , error );
}
}
main ();
Synchronous Usage (Python Only)
import os
from sudo import Sudo
with Sudo(
server_url = "https://sudoapp.dev/api" ,
api_key = os.getenv( "SUDO_API_KEY" ),
) as client:
response = client.system.health_check()
print (response)
Error Handling
Both SDKs provide comprehensive error handling:
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 ?? "" ,
});
try {
const result = await sudo . system . getSupportedModels ();
console . log ( result );
} catch ( error ) {
if ( error instanceof errors . SudoError ) {
console . log ( `SDK Error: ${ error . message } ` );
console . log ( `Status Code: ${ error . statusCode } ` );
if ( error instanceof errors . ErrorResponse ) {
console . log ( `Error Details: ${ error . data$ . error } ` );
}
}
}
Debugging
Enable debug logging to troubleshoot issues:
Using Environment Variable
Language-Specific Debug Configuration
import { Sudo } from "sudo-ai" ;
const sudo = new Sudo ({
serverURL: "https://sudoapp.dev/api" ,
apiKey: process . env . SUDO_API_KEY ?? "" ,
debugLogger: console
});
// Warning: This will reveal secrets like API tokens in console output
// Only use during local development
IDE Support
VS Code
Both SDKs work well with VS Code out of the box. For enhanced type checking:
TypeScript:
{
"typescript.preferences.includePackageJsonAutoImports" : "on"
}
Python:
{
"python.analysis.typeCheckingMode" : "strict"
}
Other IDEs
PyCharm (Python):
WebStorm (TypeScript):
TypeScript support is built-in
Enable TypeScript language service
Next Steps
Now that you have the SDK installed and configured:
Try System Endpoints - Test your setup with health checks
Create AI Responses - Start building AI-powered features
Explore Streaming - Add real-time capabilities
Both SDKs follow semantic versioning. Pin to a specific version in production to ensure stability: Python: pip install sudo-ai== 0.1.0
TypeScript: npm install sudo-ai@0.1.1