Error Tracking

Error tracking helps you identify, analyze, and resolve issues with your API requests. LangMart provides detailed error analytics to help you maintain high reliability.

Viewing Errors

Dashboard

Navigate to Analytics > Errors to view the error tracking dashboard:

  • Error summary statistics
  • Error breakdown by type
  • Recent error list with details
  • Suggested fixes for common issues

API Access

curl -X GET "https://api.langmart.ai/api/account/errors" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -G \
  -d "start_date=2025-01-01T00:00:00Z" \
  -d "end_date=2025-01-31T23:59:59Z"

Error Summary

Summary Statistics

{
  "summary": {
    "total_errors": 231,
    "error_rate": 1.5,
    "trend": -12.5,
    "days_with_errors": 28,
    "server_errors": 45,
    "client_errors": 186,
    "period": {
      "start": "2025-01-01T00:00:00Z",
      "end": "2025-01-31T23:59:59Z"
    }
  }
}

Understanding Summary Fields

Field Description
total_errors Total errors in the period
error_rate Percentage of requests that failed
trend Change from previous period (negative is good)
server_errors 5xx errors (provider/system issues)
client_errors 4xx errors (request/config issues)

Error Types

Error Breakdown

{
  "breakdown": [
    {
      "status_code": 429,
      "error_code": "PROVIDER_OPENAI_429",
      "error_type": "rate_limit_error",
      "count": 85,
      "percentage": 36.8,
      "last_occurrence": "2025-01-31T14:30:00Z"
    },
    {
      "status_code": 401,
      "error_code": "GATEWAY1_AUTH_001",
      "error_type": "authentication_error",
      "count": 52,
      "percentage": 22.5,
      "last_occurrence": "2025-01-31T12:15:00Z"
    },
    {
      "status_code": 400,
      "error_code": "API_VALIDATION_001",
      "error_type": "invalid_request_error",
      "count": 38,
      "percentage": 16.5,
      "last_occurrence": "2025-01-31T10:45:00Z"
    }
  ]
}

Common Error Types

Status Code Error Type Description
400 invalid_request_error Invalid request format or parameters
401 authentication_error Invalid or missing API key
403 forbidden Access denied to resource
404 not_found Model or resource not found
429 rate_limit_error Rate limit exceeded
500 api_error Internal server error
503 service_unavailable Gateway or provider unavailable
504 gateway_timeout Request timed out

Debugging Failed Requests

Error Details

Each error includes detailed information:

{
  "errors": [
    {
      "id": "req_abc123",
      "request_id": "req_abc123",
      "created_at": "2025-01-31T14:30:00Z",
      "method": "POST",
      "endpoint": "/v1/chat/completions",
      "response_status": 429,
      "error_code": "PROVIDER_OPENAI_429",
      "error_type": "rate_limit_error",
      "error_message": "Rate limit exceeded",
      "model_name": "gpt-4o",
      "provider_name": "OpenAI",
      "latency_ms": 450,
      "total_cost": null,
      "suggested_fix": "Rate limit exceeded. Try: 1) Reduce request rate, 2) Upgrade to higher tier, 3) Use a different model, or 4) Implement exponential backoff.",
      "severity": "high"
    }
  ]
}

Error Severity Levels

Severity Status Codes Action Required
critical 500+ Immediate investigation
high 429, 401 Review configuration
medium 403, 404 Check request parameters
low 400 Client-side fix needed

Filtering Errors

# Filter by error type
curl "https://api.langmart.ai/api/account/errors?error_type=rate_limit_error"

# Filter by status code
curl "https://api.langmart.ai/api/account/errors?status_code=429"

# Filter by model
curl "https://api.langmart.ai/api/account/errors?model=gpt-4o"

# Pagination
curl "https://api.langmart.ai/api/account/errors?limit=20&offset=0"

Common Error Codes

Authentication Errors (401)

Error Code Description Solution
GATEWAY1_AUTH_001 Invalid API key Check API key in Connections settings
PROVIDER_OPENAI_401 OpenAI auth failed Update OpenAI API key
PROVIDER_ANTHROPIC_401 Anthropic auth failed Update Anthropic API key
PROVIDER_GOOGLE_401 Google AI auth failed Update Google API key

Rate Limit Errors (429)

Error Code Description Solution
PROVIDER_OPENAI_429 OpenAI rate limit Reduce rate or upgrade tier
PROVIDER_ANTHROPIC_429 Anthropic rate limit Implement backoff
PROVIDER_GOOGLE_429 Google AI rate limit Check usage quotas
PROVIDER_OPENROUTER_429 OpenRouter rate limit Wait and retry

Validation Errors (400)

Error Code Description Solution
API_VALIDATION_001 Invalid request format Check API documentation
PROVIDER_ANTHROPIC_400 Invalid Anthropic request Review request parameters

Not Found Errors (404)

Error Code Description Solution
GATEWAY1_ROUTING_001 Model not found Check model availability
PROVIDER_OPENROUTER_POLICY Data policy restriction Enable data sharing for free models

Service Errors (500+)

Error Code Description Solution
SYSTEM_DB_001 Database error Contact support
GATEWAY_TIMEOUT_001 Gateway timeout Retry with exponential backoff
GATEWAY3_CONN_001 Gateway unavailable Check gateway status
ROUTE_SELECTION_FAILED All routes failed Check connection status

Suggested Fixes

LangMart automatically provides suggested fixes based on the error:

Rate Limiting (429)

Rate limit exceeded. Try:
1) Reduce request rate
2) Upgrade to higher tier
3) Use a different model
4) Implement exponential backoff

Authentication (401)

Invalid API key. Go to Connections settings and update your API key for this provider.

Model Not Found (404)

Model not found. This model may have been removed or renamed. Try browsing available models in the Models page.

Server Errors (500+)

Server error. This is usually temporary. Try:
1) Retry the request
2) Wait a few minutes
3) Contact support if it persists

Token Limit (400)

Token limit exceeded. Try:
1) Reduce prompt length
2) Use a model with larger context window
3) Split into multiple requests

Monitoring Error Rate Over Time

Track how your error rate changes:

curl -X GET "https://api.langmart.ai/api/account/errors" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -G \
  -d "start_date=2025-01-01" \
  -d "end_date=2025-01-31"

The trend field shows percentage change from the previous period:

  • Negative values indicate improvement
  • Positive values indicate more errors

Setting Up Error Alerts

Create alerts to be notified of error spikes:

  1. Navigate to Alerts
  2. Create a new alert with type Error Rate
  3. Set threshold (e.g., 5% error rate)
  4. Choose notification channels

Best Practices

Implementing Retry Logic

For transient errors (429, 503, 504), implement exponential backoff:

import time
import random

def make_request_with_retry(request_func, max_retries=5):
    for attempt in range(max_retries):
        try:
            return request_func()
        except RateLimitError:
            if attempt == max_retries - 1:
                raise
            wait_time = (2 ** attempt) + random.uniform(0, 1)
            time.sleep(wait_time)

Reducing Rate Limit Errors

  1. Request Queuing: Queue requests to stay under limits
  2. Caching: Cache responses for identical requests
  3. Model Diversification: Spread load across providers
  4. Tier Upgrade: Consider higher API tiers

Monitoring Best Practices

  1. Set Up Alerts: Get notified before issues escalate
  2. Regular Review: Check error trends weekly
  3. Root Cause Analysis: Investigate recurring errors
  4. Documentation: Track known issues and solutions