Documentation

Errors & Troubleshooting

V2

Understanding V2 error codes, their meanings, and how to resolve them.

Error Response Format

All V2 API errors return a consistent JSON structure:

{
  "error": {
    "type": "invalid_request_error",
    "code": "missing_field",
    "message": "The 'messages' field is required",
    "param": "messages",
    "request_id": "req-7f65ab21d1"
  }
}
FieldDescription
typeCategory of error (authentication_error, rate_limit_error, server_error, etc.)
codeSpecific error code for programmatic handling
messageHuman-readable error description
paramThe parameter that caused the error (if applicable)
request_idUnique ID for support requests
HTTP Status Codes
CodeTypeExample CodeDescriptionResolution
400invalid_request_errormissing_fieldInvalid request body or parametersCheck required fields (messages, model)
401authentication_errorinvalid_api_keyMissing or invalid API keyCheck x-api-key header
403forbidden_errorkey_revokedAPI key revoked or insufficient permissionsGenerate new key in console
404not_found_errorcontext_not_foundResource not found or context expiredVerify context_id or model name
409conflict_errorduplicate_idDuplicate external_id in same contextUse unique IDs per message
413invalid_request_errorpayload_too_largeRequest body exceeds size limitReduce message size or split batch
422invalid_request_errorinvalid_roleInvalid value for a fieldUse valid roles: user, assistant, system
429rate_limit_errortoo_many_requestsRate limit exceededRetry with exponential backoff
500server_errorinternalUnexpected server errorRetry; contact support if persistent
503server_errorservice_unavailableService temporarily unavailableCheck status page, retry later
Common Issues & Solutions

Authentication Failures (401)

  • Verify API key is correctly set in x-api-key header
  • Ensure key format is correct: kaiko_live_xxx (production) or kaiko_test_xxx (staging)
  • Check if key has been revoked in the console

Rate Limiting (429)

  • Implement exponential backoff with jitter
  • Check Retry-After header for wait time
  • Monitor X-RateLimit-Remaining header
  • Use batch analysis for multiple texts

Context Not Found (404)

  • Context IDs expire after 24 hours by default
  • Verify the context_id was created successfully
  • Check for typos in the context_id path

Invalid Model (400/404)

  • V2 emotion model: emotion-v2
  • LLM models: gpt-4, gpt-4-turbo, gpt-3.5-turbo, claude-3-*, xai-grok
  • Check model name spelling

Timeout Errors

  • Default timeout is 30 seconds for non-streaming requests
  • Use stream: true for long responses
  • Reduce message history length if hitting context limits
Retry Strategy

Use exponential backoff with jitter for transient errors (429, 500, 503):

async function callWithRetry(fn, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      // Retry on rate limit or server errors
      if (error.status === 429 || error.status >= 500) {
        const delay = Math.pow(2, i) * 1000 + Math.random() * 200;
        console.log(`Retry ${i + 1}/${maxRetries} after ${delay}ms`);
        await new Promise(r => setTimeout(r, delay));
        continue;
      }
      throw error; // Don't retry client errors (4xx except 429)
    }
  }
  throw new Error('Max retries exceeded');
}
Debugging Checklist
  • 1.Check API key is set correctly in x-api-key header
  • 2.Validate JSON payload (run through a linter)
  • 3.Confirm endpoint path matches V2 format (/v2/...)
  • 4.Check rate limit headers in response
  • 5.Log request_id for support requests
Getting Help

Next: see Rate Limits for quota details, or Changelog for recent updates.