SereChat
Apps
← Back to SereChat

Docs / Reference

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

StatusWhen it occursResolution
200Inference started successfully. Response body is an SSE stream.
400Malformed request body, unknown model ID, invalid message role, or missing required fields.Check the error field in the response body.
401Missing Authorization header, invalid token, revoked token, or expired token.Re-authorize the app to obtain a new token.
402The authorized user's SereChat balance is zero or negative.Ask the user to top up their balance at serechat.com/plan.
429Rate limit exceeded.Back off and retry with exponential backoff.
404/api/auth/app/requestrequest_id not found or expired.
/api/auth/app/exchange — request not in authorized state.
Start a new authorization flow.
410Code was entered incorrectly 5 times; the request is permanently invalidated.Start a new authorization flow.
500Unexpected 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

json
event: content
data: { "content": "Hello, world" }

Text chunk from the model. Accumulate all content events to build the complete response.

reasoning

json
event: reasoning
data: { "content": "Let me think..." }

Internal reasoning from models that support extended thinking. Optional to display to end users.

tool_calls

json
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

json
event: finish
data: {
  "finish_reason": "stop"
}
finish_reasonMeaning
stopModel finished normally.
tool_callsModel issued tool call(s). Handle them and continue.
lengthReached max_tokens limit.

error

json
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

json
event: done
data: {}

Always the last event. Close your connection after receiving it.


Authorization errors

StatusBodyDescription
400app_name requiredMissing or empty app_name in /request.
400request_id and code requiredMissing fields in /exchange.
400Invalid codeWrong code entered. Attempts remaining shown in header.
404Request not found or expiredrequest_id unknown or past its 10-minute window.
409Not yet authorizedExchange called before the user approved in the browser.
410Request invalidatedToo many wrong code attempts.