Skip to content

Troubleshooting

This guide covers common issues you might encounter when using UniCraft and provides solutions to resolve them.

Problem: Getting “Invalid API key” errors

Symptoms:

  • HTTP 401 Unauthorized errors
  • “Invalid API key” error messages
  • Authentication failures

Solutions:

  1. Check API Key Format

    Terminal window
    # Verify your API key format
    echo $UNICRAFT_API_KEY
    # Should start with 'uc_' for UniCraft keys
  2. Verify API Key Validity

    Terminal window
    # Test API key
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/health
  3. Check Environment Variables

    Terminal window
    # Ensure environment variable is set
    env | grep UNICRAFT_API_KEY
  4. Regenerate API Key

    • Log into UniCraft dashboard
    • Go to Settings → API Keys
    • Generate a new API key
    • Update your environment variables

Problem: API key has expired

Symptoms:

  • “API key expired” error messages
  • Authentication failures after working previously

Solutions:

  1. Check Key Expiration

    • Log into UniCraft dashboard
    • Check API key expiration date
    • Generate a new key if expired
  2. Set Up Key Rotation

    Terminal window
    # Enable automatic key rotation
    export UNICRAFT_API_KEY_ROTATION_ENABLED=true
    export UNICRAFT_API_KEY_ROTATION_INTERVAL=90

Problem: Provider is not responding or unavailable

Symptoms:

  • “Provider unavailable” errors
  • Timeout errors
  • 503 Service Unavailable responses

Solutions:

  1. Check Provider Status

    Terminal window
    # Check provider health
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/providers/status
  2. Test Provider Connection

    Terminal window
    # Test specific provider
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/providers/openai/test
  3. Configure Failover

    const failoverConfig = {
    enabled: true,
    fallback_providers: ["anthropic", "google"],
    retry_attempts: 3,
    };
  4. Check Provider API Keys

    Terminal window
    # Verify provider API keys
    echo $OPENAI_API_KEY
    echo $ANTHROPIC_API_KEY
    echo $GOOGLE_API_KEY

Problem: Hitting rate limits from providers

Symptoms:

  • “Rate limit exceeded” errors
  • 429 Too Many Requests responses
  • Intermittent failures

Solutions:

  1. Implement Rate Limiting

    const rateLimits = {
    requests_per_minute: 60,
    requests_per_hour: 1000,
    tokens_per_minute: 100000,
    };
  2. Use Multiple Providers

    const providers = [
    { name: "openai", weight: 0.5 },
    { name: "anthropic", weight: 0.3 },
    { name: "google", weight: 0.2 },
    ];
  3. Implement Retry Logic

    const retryConfig = {
    retry_attempts: 3,
    retry_delay: 1000,
    retry_delay_multiplier: 2,
    };
  4. Monitor Usage

    Terminal window
    # Check usage statistics
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/usage

Problem: Requested model is not available

Symptoms:

  • “Model not found” errors
  • “Model unavailable” messages
  • 404 Not Found responses

Solutions:

  1. Check Available Models

    Terminal window
    # List available models
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/models
  2. Use Smart Routing

    const response = await unicraft.chat.completions.create({
    model: "auto", // Let UniCraft choose the best model
    messages: messages,
    });
  3. Check Provider Configuration

    Terminal window
    # Verify provider models
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/providers
  4. Use Alternative Models

    const alternativeModels = ["gpt-3.5-turbo", "claude-3-haiku", "gemini-pro"];

Problem: Model responses are poor quality or slow

Symptoms:

  • Low-quality responses
  • Slow response times
  • Inconsistent results

Solutions:

  1. Optimize Prompts

    // Better prompt structure
    const prompt = `
    You are an expert in [domain].
    Please provide a detailed and accurate response to the following question:
    Question: ${userQuestion}
    Please ensure your response is:
    - Accurate and factual
    - Well-structured
    - Comprehensive but concise
    `;
  2. Adjust Model Parameters

    const response = await unicraft.chat.completions.create({
    model: "gpt-4",
    messages: messages,
    temperature: 0.7, // Adjust for creativity
    max_tokens: 1000, // Set appropriate limit
    top_p: 0.9,
    });
  3. Try Different Models

    const models = ["gpt-4", "claude-3-sonnet", "gemini-pro"];
    // Test different models for your use case
  4. Use Quality-Optimized Routing

    const routingConfig = {
    strategy: "quality_optimized",
    quality_threshold: 0.9,
    };

Problem: Spending more than expected on AI requests

Symptoms:

  • High monthly bills
  • Cost alerts
  • Budget exceeded warnings

Solutions:

  1. Set Cost Limits

    const costLimits = {
    max_cost_per_request: 0.01,
    daily_cost_limit: 100.0,
    monthly_cost_limit: 2000.0,
    };
  2. Use Cost-Optimized Routing

    const routingConfig = {
    strategy: "cost_optimized",
    max_cost_per_request: 0.005,
    quality_threshold: 0.8,
    };
  3. Implement Caching

    const cacheConfig = {
    enabled: true,
    ttl: 3600, // Cache for 1 hour
    max_size: 1000, // MB
    };
  4. Monitor Usage

    Terminal window
    # Check cost breakdown
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/analytics/costs
  5. Use Cheaper Models

    const cheapModels = ["gpt-3.5-turbo", "claude-3-haiku", "gemini-pro"];

Problem: Unexpected charges on your bill

Symptoms:

  • Higher than expected costs
  • Charges for unused services
  • Billing discrepancies

Solutions:

  1. Review Usage Reports

    Terminal window
    # Get detailed usage report
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/analytics/usage
  2. Check Cost Breakdown

    Terminal window
    # Get cost breakdown by provider/model
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/analytics/costs
  3. Set Up Alerts

    const alerts = [
    { threshold: 0.5, action: "email" },
    { threshold: 0.8, action: "slack" },
    { threshold: 1.0, action: "pause" },
    ];
  4. Audit API Usage

    • Check for unexpected API calls
    • Review application logs
    • Verify request patterns

Problem: API requests are taking too long

Symptoms:

  • High response times
  • Timeout errors
  • Poor user experience

Solutions:

  1. Optimize Requests

    // Reduce max_tokens for faster responses
    const response = await unicraft.chat.completions.create({
    model: "gpt-3.5-turbo", // Faster model
    messages: messages,
    max_tokens: 100, // Smaller response
    });
  2. Use Faster Models

    const fastModels = ["gpt-3.5-turbo", "claude-3-haiku", "gemini-pro"];
  3. Implement Caching

    const cacheConfig = {
    enabled: true,
    ttl: 3600,
    compression: true,
    };
  4. Use Performance-Optimized Routing

    const routingConfig = {
    strategy: "performance_optimized",
    response_time_limit: 2000,
    };
  5. Optimize Network

    • Use CDN for static content
    • Implement connection pooling
    • Use HTTP/2

Problem: Many requests are failing

Symptoms:

  • High error rates
  • Frequent failures
  • Unreliable service

Solutions:

  1. Implement Retry Logic

    const retryConfig = {
    retry_attempts: 3,
    retry_delay: 1000,
    exponential_backoff: true,
    };
  2. Use Circuit Breaker

    const circuitBreaker = {
    enabled: true,
    failure_threshold: 5,
    recovery_timeout: 30000,
    };
  3. Monitor Error Patterns

    Terminal window
    # Check error analysis
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/analytics/errors
  4. Implement Fallback

    const fallbackConfig = {
    enabled: true,
    fallback_providers: ["anthropic", "google"],
    fallback_models: ["gpt-3.5-turbo", "claude-3-haiku"],
    };

Problem: Configuration errors preventing service from working

Symptoms:

  • Startup failures
  • Configuration validation errors
  • Service not responding

Solutions:

  1. Validate Configuration

    Terminal window
    # Validate environment variables
    ./validate-config.sh
  2. Check Configuration Format

    // Ensure proper JSON format
    const config = {
    apiKey: process.env.UNICRAFT_API_KEY,
    baseURL: process.env.UNICRAFT_BASE_URL,
    timeout: parseInt(process.env.UNICRAFT_TIMEOUT) || 30000,
    };
  3. Test Configuration

    Terminal window
    # Test configuration
    curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
    https://api.unicraft.com/v1/health
  4. Review Documentation

    • Check configuration reference
    • Verify required fields
    • Test with minimal configuration

Problem: Issues with environment setup

Symptoms:

  • Environment variable not found
  • Configuration not loading
  • Service not starting

Solutions:

  1. Check Environment Variables

    Terminal window
    # List all UniCraft variables
    env | grep UNICRAFT
  2. Verify Environment Setup

    Terminal window
    # Check if variables are exported
    echo $UNICRAFT_API_KEY
    echo $OPENAI_API_KEY
  3. Use Environment Files

    Terminal window
    # Create .env file
    cat > .env << EOF
    UNICRAFT_API_KEY=uc_1234567890abcdef
    OPENAI_API_KEY=sk-1234567890abcdef
    ANTHROPIC_API_KEY=sk-ant-1234567890abcdef
    EOF
    # Load environment
    source .env
  4. Check Docker/Kubernetes

    # Verify environment in containers
    env:
    - name: UNICRAFT_API_KEY
    valueFrom:
    secretKeyRef:
    name: unicraft-secrets
    key: api-key
Terminal window
# Set debug log level
export UNICRAFT_LOG_LEVEL=debug
export UNICRAFT_LOG_REQUESTS=true
export UNICRAFT_LOG_RESPONSES=true
export UNICRAFT_LOG_PERFORMANCE=true
Terminal window
# View application logs
tail -f /var/log/unicraft.log
# View Docker logs
docker logs -f unicraft-container
# View Kubernetes logs
kubectl logs -f deployment/unicraft
Terminal window
# Check service health
curl https://api.unicraft.com/v1/health
# Check provider status
curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
https://api.unicraft.com/v1/providers/status
Terminal window
# Get performance metrics
curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
https://api.unicraft.com/v1/analytics/metrics
# Get usage statistics
curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
https://api.unicraft.com/v1/analytics/usage
Terminal window
# Test basic functionality
curl -X POST \
-H "Authorization: Bearer $UNICRAFT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "auto", "messages": [{"role": "user", "content": "Hello"}]}' \
https://api.unicraft.com/v1/chat/completions
Terminal window
# Test specific provider
curl -H "Authorization: Bearer $UNICRAFT_API_KEY" \
https://api.unicraft.com/v1/providers/openai/test
  1. Documentation

  2. Community

  3. Status Page

  1. Email Support

  2. Priority Support

    • Available for enterprise customers
    • 24/7 support for critical issues
    • Direct access to engineering team
  3. Bug Reports

    • GitHub Issues
    • Include detailed reproduction steps
    • Provide logs and error messages
  1. Check Documentation

    • Review relevant documentation
    • Check troubleshooting guides
    • Verify configuration
  2. Gather Information

    • Error messages and logs
    • Configuration details
    • Reproduction steps
    • Environment information
  3. Try Common Solutions

    • Restart service
    • Check API keys
    • Verify network connectivity
    • Test with minimal configuration
  1. Monitoring

    • Set up health checks
    • Monitor error rates
    • Track performance metrics
    • Set up alerts
  2. Configuration

    • Use environment variables
    • Validate configuration
    • Test in staging environment
    • Document setup
  3. Error Handling

    • Implement retry logic
    • Use circuit breakers
    • Handle failures gracefully
    • Log errors properly
  4. Security

    • Rotate API keys regularly
    • Use secure storage
    • Monitor for unusual activity
    • Implement access controls
  1. Weekly

    • Review error logs
    • Check performance metrics
    • Monitor costs
    • Update dependencies
  2. Monthly

    • Review configuration
    • Update API keys
    • Analyze usage patterns
    • Optimize costs
  3. Quarterly

    • Security audit
    • Performance review
    • Capacity planning
    • Disaster recovery testing

After resolving issues:

  1. Document Solutions: Record solutions for future reference
  2. Update Monitoring: Improve monitoring based on issues encountered
  3. Prevent Recurrence: Implement measures to prevent similar issues
  4. Share Knowledge: Share solutions with team members
  5. Continuous Improvement: Regularly review and improve processes