Errors & Events
HTTP error codes returned by the API and the SSE event types you'll encounter during a streaming inference response.
HTTP error codes
| Status | When it occurs | Resolution |
|---|---|---|
| 200 | Inference started successfully. Response body is an SSE stream. | — |
| 400 | Malformed request body, unknown model ID, invalid message role, or missing required fields. | Check the error field in the response body. |
| 401 | Missing Authorization header, invalid token, revoked token, or expired token. | Re-authorize the app to obtain a new token. |
| 402 | The authorized user's SereChat balance is zero or negative. | Ask the user to top up their balance at serechat.com/plan. |
| 429 | Rate limit exceeded. | Back off and retry with exponential backoff. |
| 404 | /api/auth/app/request — request_id not found or expired./api/auth/app/exchange — request not in authorized state. | Start a new authorization flow. |
| 410 | Code was entered incorrectly 5 times; the request is permanently invalidated. | Start a new authorization flow. |
| 500 | Unexpected server error. | Retry after a short delay. If persistent, contact support. |
SSE event reference
The inference stream uses named SSE events. Read the current event: line, then parse the JSON in the following data: line.
content
event: content
data: { "content": "Hello, world" }Text chunk from the model. Accumulate all content events to build the complete response.
reasoning
event: reasoning
data: { "content": "Let me think..." }Internal reasoning from models that support extended thinking. Optional to display to end users.
tool_calls
event: tool_calls
data: {
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Amsterdam\"}"
}
}
]
}The model wants to call one or more functions. Execute them, then append the results as tool role messages and call the inference endpoint again. The finish event will have "finish_reason": "tool_calls".
finish
event: finish
data: {
"finish_reason": "stop"
}| finish_reason | Meaning |
|---|---|
| stop | Model finished normally. |
| tool_calls | Model issued tool call(s). Handle them and continue. |
| length | Reached max_tokens limit. |
error
event: error
data: { "error": "Inference failed unexpectedly" }A non-fatal mid-stream error. The stream may still close normally after this. If the error is unrecoverable, a done event follows immediately.
done
event: done
data: {}Always the last event. Close your connection after receiving it.
Authorization errors
| Status | Body | Description |
|---|---|---|
| 400 | app_name required | Missing or empty app_name in /request. |
| 400 | request_id and code required | Missing fields in /exchange. |
| 400 | Invalid code | Wrong code entered. Attempts remaining shown in header. |
| 404 | Request not found or expired | request_id unknown or past its 10-minute window. |
| 409 | Not yet authorized | Exchange called before the user approved in the browser. |
| 410 | Request invalidated | Too many wrong code attempts. |