Error Handling
Comprehensive guide to error handling in the Bike4Mind API, including error codes, response formats, and troubleshooting.
Error Response Format
All API errors follow a standardized format:
{
"error": {
"code": "ERROR_CODE",
"message": "Human-readable error description",
"details": {
"field": "additional context",
"timestamp": "2024-01-15T10:30:00Z"
}
}
}
HTTP Status Codes
| Code | Description | Usage |
|---|---|---|
| 200 | Success | Successful GET, PUT operations |
| 201 | Created | Successful POST operations |
| 204 | No Content | Successful DELETE operations |
| 400 | Bad Request | Invalid request format or parameters |
| 401 | Unauthorized | Invalid or missing authentication |
| 403 | Forbidden | Insufficient permissions |
| 404 | Not Found | Resource does not exist |
| 409 | Conflict | Resource already exists or state conflict |
| 422 | Validation Error | Request data validation failed |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Server-side error |
Authentication Errors (401)
Invalid Token
{
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid or expired token"
}
}
Missing Token
{
"error": {
"code": "MISSING_TOKEN",
"message": "Authorization header is required"
}
}
Token Expired
{
"error": {
"code": "TOKEN_EXPIRED",
"message": "JWT token has expired",
"details": {
"expiredAt": "2024-01-15T10:30:00Z"
}
}
}
Authorization Errors (403)
Insufficient Permissions
{
"error": {
"code": "FORBIDDEN",
"message": "Insufficient permissions for this operation",
"details": {
"required": "create:notebook",
"userPermissions": ["read:notebook"]
}
}
}
Account Suspended
When an administrator suspends the account that owns your API key or session, every authenticated request returns 403 with errorCode: "account_suspended". Suspension also disables the account's API keys, but a request made with one of them still gets this 403 rather than a 401, so you can tell a suspension from a wrong key. Retrying or rotating the key does not help. If the account is reinstated, its old keys stay disabled; create new ones.
{
"error": "This account is suspended for automated or scripted misuse of the service, which our Usage Policy does not allow. If you believe this is a mistake, you can appeal at https://example.com/support.",
"errorCode": "account_suspended",
"suspension": {
"reason_category": "automated_misuse",
"terms_url": "https://example.com/usage-policy",
"appeal_url": "https://example.com/support"
},
"request_id": "req_123"
}
reason_category is one of multiple_accounts, automated_misuse, payment_fraud, prohibited_content or terms_violation. New categories may be added, so treat an unknown value like terms_violation. terms_url and appeal_url are absent on self-hosted deployments. Branch on errorCode, not on the message text.
Organization Access Denied
{
"error": {
"code": "ORG_ACCESS_DENIED",
"message": "Access denied to organization resources",
"details": {
"organizationId": "org_123"
}
}
}
Validation Errors (422)
Single Field Error
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input parameters",
"details": {
"field": "email",
"issue": "Invalid email format"
}
}
}
Multiple Field Errors
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Multiple validation errors",
"details": [
{
"field": "email",
"message": "Email is required"
},
{
"field": "password",
"message": "Password must be at least 8 characters"
}
]
}
}
Resource Errors (404)
Resource Not Found
{
"error": {
"code": "NOT_FOUND",
"message": "The requested resource was not found",
"details": {
"resource": "user",
"id": "user_123"
}
}
}
Endpoint Not Found
{
"error": {
"code": "ENDPOINT_NOT_FOUND",
"message": "API endpoint does not exist",
"details": {
"path": "/api/invalid-endpoint",
"method": "GET"
}
}
}
Rate Limiting Errors (429)
Rate Limit Exceeded
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests",
"details": {
"limit": 100,
"window": "1 minute",
"resetAt": "2024-01-15T10:31:00Z"
}
}
}
Agent-Specific Errors
Agent Not Found
{
"error": {
"code": "AGENT_NOT_FOUND",
"message": "The specified agent could not be found",
"details": {
"agentId": "agent_123"
}
}
}
Agent Already Attached
{
"error": {
"code": "AGENT_ALREADY_ATTACHED",
"message": "Agent is already attached to this session",
"details": {
"agentId": "agent_123",
"sessionId": "session_456"
}
}
}
Agent Limit Exceeded
{
"error": {
"code": "AGENT_LIMIT_EXCEEDED",
"message": "Maximum number of agents exceeded",
"details": {
"limit": 5,
"current": 5
}
}
}
Subscription Errors
Subscription Required
{
"error": {
"code": "SUBSCRIPTION_REQUIRED",
"message": "This feature requires an active subscription",
"details": {
"feature": "advanced_agents",
"requiredTier": "pro"
}
}
}
Insufficient Credits
Out-of-credit failures return 422 with errorCode: "insufficient_credits", or arrive as an in-band error event on an open stream. See Completions API errors.
Server Errors (500)
Internal Server Error
{
"error": {
"code": "INTERNAL_ERROR",
"message": "An internal server error occurred",
"details": {
"requestId": "req_123456",
"timestamp": "2024-01-15T10:30:00Z"
}
}
}
Service Unavailable
{
"error": {
"code": "SERVICE_UNAVAILABLE",
"message": "Service temporarily unavailable",
"details": {
"service": "ai_inference",
"retryAfter": 30
}
}
}
Rate Limit Headers
When rate limits are approached or exceeded, responses include these headers:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 5
X-RateLimit-Reset: 1642284600
X-RateLimit-Retry-After: 60
Error Handling Best Practices
- Branch on the HTTP status and the error code (
errorCodeon completions endpoints,error.codeon platform endpoints), never on the message text. Parse defensively in case the body is not JSON. - On a 429, wait the
Retry-Afterseconds. Retry 500 and 503 with exponential backoff. Never retry 400, 401, 403, 413 or 422: the same request fails again. - Refresh an expired token (
TOKEN_EXPIRED) once, then replay the request. - On a 422 with
errorCode: "insufficient_credits", send the user to billing instead of retrying. - Log the status, code and request id, and leave out tokens and request bodies.
The retry table and the in-stream error codes are in Completions errors. Ready-made retry helpers are in the JavaScript and Python examples.
Troubleshooting Guide
Common Issues
401 Unauthorized
- Check if JWT token is included in Authorization header
- Verify token hasn't expired
- Ensure token is properly formatted:
Bearer <token>
403 Forbidden
- A 403 with
errorCode: "account_suspended"means the account is suspended; see Account Suspended. On the completions endpoint, a 403 withoutrequired_scopesor anerrorCodemay mean the account is under a payment dispute (contact support), or a JWT caller needs to enroll in MFA in the web app. Changing key scopes does not resolve these account restrictions - Verify user has required permissions
- Check organization membership
- Confirm subscription tier supports the feature
422 Validation Error
- Review request body format
- Check required fields are present
- Validate data types and formats
429 Rate Limited
- Implement exponential backoff
- Check rate limit headers
- Consider caching responses to reduce calls
500 Internal Error
- Retry the request after a delay
- Check API status page
- Contact support if persistent
Getting Help
If you encounter persistent errors:
- Check GitHub Discussions for known issues
- Review your API usage patterns
- Contact support with the error details and request ID
- Include relevant request/response data (without sensitive information)