SDK Examples
SDK Examples
Complete code examples for integrating AgentWall with your agent frameworks and applications.
Quick Start
Choose your language and framework:
Python
- Python SDK Guide - Complete Python integration guide
- Basic chat completions
- Run-level tracking for multi-step tasks
- Streaming responses
- LangChain integration
- CrewAI integration
- Error handling
- Budget tracking
JavaScript/TypeScript
- JavaScript SDK Guide - Complete JavaScript/TypeScript guide
- Basic chat completions
- TypeScript client class
- Run-level tracking
- Streaming with React
- LangChain.js integration
- Error handling
- Budget tracking
Framework Integrations
Python Frameworks
LangChain
CrewAI
AutoGen
JavaScript Frameworks
LangChain.js
React
Common Patterns
Multi-Step Task with Run Tracking
Python:
JavaScript:
Streaming Responses
Python:
JavaScript:
Error Handling
Python:
JavaScript:
API Key Management
Getting Your API Key
- Go to https://agentwall.io/admin
- Navigate to "API Keys"
- Click "Create New Key"
- Copy the key (format:
aw-xxxxx)
Using API Keys Securely
Python:
JavaScript:
.env file:
Best Practices
1. Always Use Run IDs for Multi-Step Tasks
Enables loop detection and cost tracking across the entire task.
2. Handle Streaming Properly
Use streaming for better UX and real-time feedback on long responses.
3. Implement Error Handling
Catch and handle API errors gracefully, especially 429 (loop detected) and 401 (auth failed).
4. Monitor Costs
Track spending to stay within budget limits.
5. Use Type Hints (Python) / TypeScript
Better IDE support and fewer runtime errors.
6. Implement Retry Logic
Handle transient failures with exponential backoff.
Troubleshooting
Loop Detection Blocking Requests (429)
Problem: Getting 429 Loop detected errors
Solution:
- Check if you're sending the same prompt repeatedly
- Use different run IDs for different tasks
- Verify your agent logic isn't stuck in a loop
Authentication Errors (401)
Problem: Getting 401 Unauthorized errors
Solution:
- Verify your API key is correct
- Check the key hasn't been revoked
- Ensure the key is passed in the Authorization header
Timeout Issues
Problem: Requests timing out
Solution:
- Increase the timeout value
- Check your network connection
- Verify the API is responding (check
/healthendpoint)
Streaming Not Working
Problem: Streaming responses aren't working
Solution:
- Ensure
stream: trueis set in the payload - Check that your client supports streaming
- Verify the response body is readable
Performance Tips
- Reuse client instances - Don't create a new client for each request
- Use connection pooling - For high-volume applications
- Implement caching - Cache responses when appropriate
- Monitor latency - Track response times to identify bottlenecks
- Use streaming - For long responses to improve perceived performance
Security Tips
- Never hardcode API keys - Use environment variables
- Rotate keys regularly - Change keys periodically
- Use HTTPS only - Always use secure connections
- Validate responses - Check response structure before processing
- Handle sensitive data - Be careful with PII in prompts
Next Steps
- Read the Python SDK Guide for detailed Python examples
- Read the JavaScript SDK Guide for detailed JavaScript examples
- Check out LangChain Integration
- Read CrewAI Integration
- Explore API Reference
- Review Concepts for architectural details
Support
- Documentation: https://docs.agentwall.io
- API Status: https://api.agentwall.io/health
- Dashboard: https://agentwall.io/admin
- Issues: Report bugs on GitHub
Motto: Guard the Agent, Save the Budget 🛡️