Errors and limits
Error format, HTTP status codes, request limits and billing for incomplete requests.
Error format
All errors use this JSON body:
{
"error": {
"message": "The request is invalid.",
"type": "invalid_request_error",
"code": "funkyrouter_invalid_request",
"request_id": "…",
"status": 400,
"retryable": false
}
}Use code in your error handling. Do not use message, because its text can change. If retryable is true, you can send the request again.
Status codes
| Status | code | Cause | Retry |
|---|---|---|---|
| 400 | funkyrouter_invalid_request | A field is not accepted or out of range, the model ID is incorrect, an image is not accepted, or the prompt plus maximum output is more than the context window. | No |
| 401 | funkyrouter_unauthorized | The key is missing, incorrect or revoked, or the request has more than one authorization header. | No |
| 402 | saddle_required | The workspace has no active FunkyRouter Credits plan. | No |
| 402 | funkyrouter_insufficient_credits | The workspace does not have sufficient credit. | No |
| 402 | funkyrouter_customer_budget_exceeded | A customer budget stops the request. | No |
| 403 | funkyrouter_forbidden | The key is a management key. | No |
| 404 | funkyrouter_not_found | The path is not a public API path. | No |
| 405 | funkyrouter_method_not_allowed | The HTTP method is incorrect. | No |
| 413 | funkyrouter_request_too_large | The body is too large. | No |
| 415 | funkyrouter_unsupported_media_type | The Content-Type is not application/json, or the body is compressed. | No |
| 429 | funkyrouter_rate_limited | The workspace sent too many requests. | After Retry-After |
| 429 | funkyrouter_capacity_unavailable | All nodes are busy. | Yes |
| 502 | funkyrouter_upstream_error | The model service sent an incorrect response. | Yes |
| 503 | funkyrouter_unavailable | No node is ready. | Yes |
| 504 | funkyrouter_timeout | The request did not complete in the time limit. | Yes |
An unknown model ID gives HTTP 400, not 404.
For retries, wait before each attempt and increase the wait each time. When the response has a Retry-After header, wait for that number of seconds.
Limits
| Limit | Value |
|---|---|
| Context window | 1,048,576 tokens, prompt plus output |
| Maximum output | Up to the context window, less the prompt. No default. |
| Streaming | Necessary when the prompt is more than 131,072 tokens. If not, the API returns HTTP 400. |
| Images | Base64 data URLs of PNG, JPEG, GIF or WebP, in user messages only. Each side 40 to 4,096 pixels. A remote URL or a file_id gives HTTP 400. |
| Messages or input items | 64 per request |
| Tools | 64 per request |
| Request body | 8 MiB. Over the limit, the API returns HTTP 413. |
| Request time | 300 seconds, plus more time for long prompts and long output. 2 hours at most. Over the limit, the API returns HTTP 504, or an error event in a stream. |
| Request rate | A limit for each workspace. Over the limit, the API returns HTTP 429 with Retry-After. |
A response that is not streamed sends nothing until it is complete. The connection can close after approximately 100 seconds. Stream long answers.
A long prompt takes time before the first token. When a stream has no output after 15 seconds, the gateway opens the stream and keeps it open. After that, an error comes as an error event in the stream, not as an HTTP status.
When all nodes are busy, the gateway holds a request in a queue for a short time. If no node becomes free, the API returns HTTP 429 with funkyrouter_capacity_unavailable.
Response headers
| Header | Content |
|---|---|
X-Request-ID | A unique ID for the request. Give it when you report a problem. |
X-FunkyRouter-Region | The region that served the request, for example texas. |
Retry-After | Seconds to wait. Sent with some 429 responses. |
Billing for incomplete requests
When a node reports token usage, FunkyRouter charges that usage. When a node does not report usage, FunkyRouter estimates it from the size of the request and the output:
| Event | Charge |
|---|---|
| You cancel after a node accepted the request | Input and all output that the node made |
| The time limit ends, streamed request | Input and the output that you received |
| The time limit ends, request not streamed | Input only |
| The node fails after it sent output, streamed request | Input and the output that you received |
| The node fails, request not streamed | No charge |
| The request fails before a node accepts it or before output starts | No charge |
The charge is never more than the credit that the gateway reserved for the request.
Last updated on