Skip to main content

Overview

The Junis External API uses conventional HTTP status codes to indicate the success or failure of a request. Error responses include a structured JSON body with details about the error, making it easy to debug and handle errors programmatically. Base URL: https://api.junis.ai

Error Response Format

Standard Error Response

All error responses follow this consistent structure:

Structured Error Response

For more complex errors (like rate limiting or scope validation), the API returns additional context:

HTTP Status Codes


Common Error Codes

Authentication Errors (401)

Description: No API key provided in request headers.Causes:
  • Missing X-API-Key header
  • Empty X-API-Key header value
Response Example:
Response Headers:
Solution:
Description: API key not found, revoked, or expired.Causes:
  • API key deleted by organization admin
  • API key revoked
  • Wrong API key format
  • API key expired (if expiration was set)
Response Example:
Solution:
  • Verify API key in Admin → API Keys
  • Generate new API key if revoked or expired
  • Check API key format: jns_live_ prefix + 32 characters

Authorization Errors (403)

Description: API key lacks required scopes for the operation.Causes:
  • API key created without required scopes
  • API key missing orchestrator:invoke scope (required for chat completions)
  • API key missing sessions:read or sessions:messages scope
Response Example:
Solution:
  • Check API key scopes in Admin → API Keys
  • Create new API key with required scopes:
    • orchestrator:invoke - Chat completions (both streaming and non-streaming)
    • sessions:read - List sessions and get session status
    • sessions:messages - Get session messages
Description: API key belongs to a different organization.Causes:
  • Trying to access sessions created by another organization
  • Trying to access resources not owned by your organization
Response Example:
Solution:
  • Verify you’re using the correct API key for your organization
  • Each API key can only access its own organization’s resources

Validation Errors (400)

Description: Request body validation failed.Causes:
  • Missing required fields
  • Invalid field types
  • Failed Pydantic validation
Response Example:
Solution:
  • Check API documentation for required fields
  • Verify data types match schema
  • Example valid request:
Description: Malformed JSON in request body.Causes:
  • Syntax error in JSON
  • Unescaped special characters
  • Trailing commas
Response Example:
Solution:
  • Validate JSON syntax using a linter
  • Escape special characters properly
  • Remove trailing commas

Resource Errors (404)

Description: Chat session does not exist.Causes:
  • Session deleted
  • Wrong session_id
  • Session belongs to different organization
Response Example:
Solution:
  • Verify session_id is correct
  • Create new session via Chat Completions API
  • List available sessions: GET /api/external/sessions
Description: Message does not exist in session.Causes:
  • Invalid message index
  • Session has no messages yet
Response Example:
Solution:
  • Check session messages: GET /api/external/sessions/{id}/messages
  • Verify message index is within range

Rate Limit Errors (429)

Description: Too many requests in time window.Response Example:
Response Headers:
Solution:
  • Wait for retry_after seconds before retrying
  • Implement exponential backoff
  • Monitor X-RateLimit-Remaining-* headers
  • Request higher rate limits in Admin → API Keys
  • Cache responses to reduce request frequency
See Rate Limits for more details.

Payload Errors (413)

Description: Request body exceeds size limit.Causes:
  • Large message content
  • Too many messages in array
  • Maximum payload: 10MB
Response Example:
Solution:
  • Split large requests into smaller chunks
  • Summarize long messages
  • Use pagination for message history

Server Errors (500)

Description: Unexpected server error occurred.Causes:
  • Database connection failure
  • External service timeout
  • Unhandled exception
Response Example:
Solution:
  • Retry request after a few seconds with exponential backoff
  • Check Status Page for incidents
  • Contact support if error persists: contact@junis.ai
Description: LLM provider (Anthropic, OpenAI) unavailable.Causes:
  • Anthropic API outage
  • OpenAI API rate limits
  • Network timeout to LLM provider
Response Example:
Solution:
  • Retry request with exponential backoff
  • Check Anthropic Status
  • Wait a few minutes and retry
Description: Agent orchestration failed.Causes:
  • Agent not found
  • Agent configuration error
  • Tool execution failure
Response Example:
Solution:
  • Retry request
  • Simplify prompt if issue persists
  • Contact support with session_id for debugging

Error Handling Best Practices

Retry Logic

Implement exponential backoff for transient errors (429, 500+ status codes):
  • 429 Rate Limit: Use the Retry-After header value to wait before retrying
  • 5xx Server Errors: Use exponential backoff (1s, 2s, 4s, etc.)
  • Max Retries: Limit to 3-5 attempts to avoid infinite loops
  • Client Errors (4xx): Do not retry, fix the request instead

Error Logging

Log errors with sufficient context for debugging:
  • Include: Timestamp, status code, error message, request URL, method
  • Exclude: Full API key (log only prefix like jns_live_abc...)
  • Structured Logging: Use JSON format for easier parsing

User-Friendly Error Messages

Present errors to users in a helpful way:
  • 401 Unauthorized: “Invalid API key. Please check your credentials.”
  • 403 Forbidden: “Permission denied. Check your API key scopes.”
  • 429 Rate Limit: “Too many requests. Please wait seconds.”
  • 5xx Server Errors: “Our servers are experiencing issues. Please try again.”
  • Generic Fallback: Use the detail field from the error response

Debugging Tools

Check API Status

Healthy Response:

Test API Key Authentication

Success Response (200 OK):
Error Response (401 Unauthorized):

Inspect Rate Limits

Response Headers:

Monitoring and Alerts

Track Error Rates

Monitor these metrics for your API integration:

Success Rate

Track 2xx responses vs total requestsTarget: > 99% success rate

4xx Errors

Client errors (auth, validation, rate limits)Alert: > 5% of requests

5xx Errors

Server errors (outages, timeouts)Alert: Any occurrence

Response Time

P50, P95, P99 latencyTarget: P95 < 2 seconds

Sample Monitoring Code


Need Help?

API Status

Check real-time API status and incidents

Rate Limits

Learn about rate limiting and optimization

Authentication

Review API key authentication

Support

Contact support for assistance