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
2xx Success
2xx Success
| Status Code | Name | Description |
|---|---|---|
| 200 | OK | Request succeeded. |
| 201 | Created | Resource successfully created. |
| 202 | Accepted | Request accepted for processing (async operations). |
| 204 | No Content | Request succeeded with no response body. |
4xx Client Errors
4xx Client Errors
| Status Code | Name | Description |
|---|---|---|
| 400 | Bad Request | Invalid request parameters or malformed JSON. |
| 401 | Unauthorized | Missing or invalid API key. |
| 403 | Forbidden | Authenticated but insufficient permissions (scopes). |
| 404 | Not Found | Resource does not exist. |
| 413 | Payload Too Large | Request body exceeds size limit. |
| 429 | Too Many Requests | Rate limit exceeded. |
5xx Server Errors
5xx Server Errors
| Status Code | Name | Description |
|---|---|---|
| 500 | Internal Server Error | Unexpected server error. |
| 502 | Bad Gateway | Upstream service unavailable. |
| 503 | Service Unavailable | Server temporarily overloaded or down. |
| 504 | Gateway Timeout | Upstream service timeout. |
Common Error Codes
Authentication Errors (401)
missing_api_key
missing_api_key
Description: No API key provided in request headers.Causes:Response Headers:Solution:
- Missing
X-API-Keyheader - Empty
X-API-Keyheader value
invalid_api_key
invalid_api_key
Description: API key not found, revoked, or expired.Causes:Solution:
- API key deleted by organization admin
- API key revoked
- Wrong API key format
- API key expired (if expiration was set)
- 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)
insufficient_scopes
insufficient_scopes
Description: API key lacks required scopes for the operation.Causes:Solution:
- API key created without required scopes
- API key missing
orchestrator:invokescope (required for chat completions) - API key missing
sessions:readorsessions:messagesscope
- 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 statussessions:messages- Get session messages
organization_access_denied
organization_access_denied
Description: API key belongs to a different organization.Causes:Solution:
- Trying to access sessions created by another organization
- Trying to access resources not owned by your organization
- 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)
invalid_input
invalid_input
Description: Request body validation failed.Causes:Solution:
- Missing required fields
- Invalid field types
- Failed Pydantic validation
- Check API documentation for required fields
- Verify data types match schema
- Example valid request:
invalid_json
invalid_json
Description: Malformed JSON in request body.Causes:Solution:
- Syntax error in JSON
- Unescaped special characters
- Trailing commas
- Validate JSON syntax using a linter
- Escape special characters properly
- Remove trailing commas
Resource Errors (404)
session_not_found
session_not_found
Description: Chat session does not exist.Causes:Solution:
- Session deleted
- Wrong session_id
- Session belongs to different organization
- Verify session_id is correct
- Create new session via Chat Completions API
- List available sessions:
GET /api/external/sessions
message_not_found
message_not_found
Description: Message does not exist in session.Causes:Solution:
- Invalid message index
- Session has no messages yet
- Check session messages:
GET /api/external/sessions/{id}/messages - Verify message index is within range
Rate Limit Errors (429)
rate_limit_exceeded
rate_limit_exceeded
Description: Too many requests in time window.Response Example:Response Headers:Solution:
- Wait for
retry_afterseconds before retrying - Implement exponential backoff
- Monitor
X-RateLimit-Remaining-*headers - Request higher rate limits in Admin → API Keys
- Cache responses to reduce request frequency
Payload Errors (413)
payload_too_large
payload_too_large
Description: Request body exceeds size limit.Causes:Solution:
- Large message content
- Too many messages in array
- Maximum payload: 10MB
- Split large requests into smaller chunks
- Summarize long messages
- Use pagination for message history
Server Errors (500)
internal_server_error
internal_server_error
Description: Unexpected server error occurred.Causes:Solution:
- Database connection failure
- External service timeout
- Unhandled exception
- Retry request after a few seconds with exponential backoff
- Check Status Page for incidents
- Contact support if error persists: [email protected]
llm_service_unavailable
llm_service_unavailable
orchestrator_error
orchestrator_error
Description: Agent orchestration failed.Causes:Solution:
- Agent not found
- Agent configuration error
- Tool execution failure
- 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-Afterheader 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
detailfield from the error response
Debugging Tools
Check API Status
Test API Key Authentication
Inspect Rate Limits
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
