JavaScript/TypeScript SDK Guide

JavaScript/TypeScript SDK Guide

Learn how to integrate AgentWall with your JavaScript/TypeScript agent frameworks.

Installation

Basic Usage

Simple Chat Completion

TypeScript Client

Run-Level Tracking

Track multi-step agent tasks:

Streaming with React

LangChain.js Integration

Error Handling

Budget Tracking

Best Practices

  1. Always use run IDs for multi-step tasks - Enables loop detection and cost tracking
  2. Handle streaming properly - Use async iterators for better performance
  3. Implement error boundaries - Catch and handle API errors gracefully
  4. Monitor costs - Track spending to stay within budget
  5. Use TypeScript - Better type safety and IDE support
  6. Implement retry logic - Handle transient failures with exponential backoff

Troubleshooting

Loop Detection Blocking Requests

If you see 429 Loop detected errors:

  • 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

Streaming Not Working

If streaming responses aren't working:

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

Authentication Errors

If you see 401 Unauthorized:

  • Verify your API key is correct
  • Check the key hasn't been revoked
  • Ensure the key is passed in the Authorization header

Next Steps