Development Guide
This guide provides advanced tips, best practices, and examples for developers working with the Klen AI API. Use this information to build robust, scalable integrations with our platform.API Architecture
The Klen AI API is a RESTful API that uses standard HTTP methods and returns JSON responses. The base URL for all API requests is:GET
requests for retrieving resourcesPOST
requests for creating resourcesPUT
/PATCH
requests for updating resourcesDELETE
requests for deleting resources (when applicable)
Error Handling
The API returns appropriate HTTP status codes and error messages to help you troubleshoot issues:Status Code | Error Code | Description |
---|---|---|
400 | validation_error | Invalid input parameters |
401 | authentication_required | No API key provided |
401 | invalid_key | Invalid or inactive API key |
403 | permission_denied | API key lacks required permission |
404 | not_found | Requested resource not found |
429 | rate_limit_exceeded | Rate limit exceeded |
500 | server_error | Internal server error |
Pagination
List endpoints support pagination through thepage
and limit
query parameters:
Rate Limiting
Our API implements rate limiting to ensure the stability of the service. Rate limits are enforced on a per-API-key basis. When you exceed the rate limit, you’ll receive a429 Too Many Requests
status code with a Retry-After
header indicating when you can make your next request.
Retry-After
header and implementing exponential backoff strategies.
Best Practices
Security
- Store API Keys Securely: Never hardcode API keys in your source code or expose them in client-side JavaScript.
- Use Environment Variables: Store your API keys in environment variables or a secure key management system.
- Implement IP Allowlisting: Use the Klen AI dashboard to restrict access to your API keys from specific IP addresses.
- Create Scoped Keys: Create API keys with the minimum required permissions for each use case.
Performance
- Optimize Batch Operations: Use batch endpoints where available instead of making many individual requests.
- Implement Caching: Cache responses for resources that don’t change frequently.
- Use Compression: Enable gzip compression for API requests and responses to reduce bandwidth usage.
- Filter Results: Use query parameters to filter results on the server side rather than retrieving all data and filtering client-side.
Webhooks
- Verify Webhook Signatures: Always verify the signature of incoming webhook requests using the secret provided when creating the webhook.
- Implement Idempotency: Handle webhook events idempotently to avoid duplicate processing.
- Acknowledge Quickly: Respond to webhook requests with a 2xx status code as quickly as possible, then process the event asynchronously.
Working with Agents
When creating or updating AI agents, you can customize various aspects of their behavior:Agent Persona
Provide detailed instructions to shape your agent’s personality, tone, and behavior:Context Variables
Use context variables to provide dynamic information to your agents during calls:{{variable_name}}
syntax.
Testing
We provide a sandbox environment for testing your integration without making real phone calls:- No real calls are made
- No charges are incurred
- Test data is automatically generated
- API responses mimic production behavior
Implementing Webhooks
Receiving Webhooks
Here’s an example of how to receive and verify webhook events using Node.js and Express:Webhook Event Types
Refer to our Webhook Events documentation for a complete list of available webhook events and their payloads.Need Help?
If you need assistance with your integration, you can:- Consult our API Reference
- Contact our Support