@legionai/sdk
v0.1.0
Published
Connect your app to Legion wallets and let users pay for AI with their own funds.
Maintainers
Readme
Legion SDK
Connect your app to Legion wallets and let users pay for AI with their own funds.
Installation
npm install @legionai/sdkQuick Example
import { createLegion } from '@legionai/sdk';
const legion = createLegion({
clientId: 'your_client_id',
});
// Connect user's wallet
legion.connect({ redirectUri: 'https://yourapp.com/callback' });
// After callback, exchange code for tokens
const tokens = await legion.exchangeCode(code);
// Make API calls - costs come from user's wallet
const response = await legion.chat([
{ role: 'user', content: 'Hello!' }
]);Documentation
- Quickstart - Get started in 5 minutes
- Authentication Guide - OAuth flow, tokens, and session management
- Error Handling - Handle errors gracefully
- API Reference - Complete API documentation
How It Works
- User authorizes your app to use their Legion wallet
- You get tokens to make API calls on their behalf
- AI costs are charged to the user's wallet, not yours
- Users control spending limits and can deactivate anytime
Key Features
- Zero AI costs for developers - Users pay from their own wallets
- Simple OAuth flow - Standard authorization, familiar to users
- Auto token refresh - SDK handles token lifecycle automatically
- Graceful error handling - Structured errors with helper methods
- User control - Users set limits and can disconnect anytime
Error Handling
try {
await legion.chat(messages);
} catch (error) {
if (error.requiresReauth()) {
legion.connect(); // Re-authorize
} else if (error.isBillingError()) {
showMessage('Please add funds to your Legion wallet');
}
}Support
- Documentation: docs/
- Issues: GitHub Issues
License
MIT
