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

  1. Go to https://agentwall.io/admin
  2. Navigate to "API Keys"
  3. Click "Create New Key"
  4. 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 /health endpoint)

Streaming Not Working

Problem: Streaming responses aren't working

Solution:

  • Ensure stream: true is set in the payload
  • Check that your client supports streaming
  • Verify the response body is readable

Performance Tips

  1. Reuse client instances - Don't create a new client for each request
  2. Use connection pooling - For high-volume applications
  3. Implement caching - Cache responses when appropriate
  4. Monitor latency - Track response times to identify bottlenecks
  5. Use streaming - For long responses to improve perceived performance

Security Tips

  1. Never hardcode API keys - Use environment variables
  2. Rotate keys regularly - Change keys periodically
  3. Use HTTPS only - Always use secure connections
  4. Validate responses - Check response structure before processing
  5. Handle sensitive data - Be careful with PII in prompts

Next Steps

Support


Motto: Guard the Agent, Save the Budget 🛡️