My streaming code crashes with "choices[0] is undefined". Why?
When you set stream_options: {"include_usage": true}, the last chunk carries usage and an empty choices array. Indexing choices[0] on it crashes.
const t = chunk.choices[0]?.delta?.content; // JavaScript
if chunk.choices and chunk.choices[0].delta.content: # Python
...
Good to know#
- Model ids:
supercosmos-flash,supercosmos-max,supercosmos-heavy(SuperCosmos 1.1). Which to call - If calls fail unexpectedly, check status.clatterlabs.com before debugging further.
- Your key's account is responsible for your end users' text under the Abuse policy. What it means for apps
Still need help?#
- General support: support@clatterlabs.com or team@clatterlabs.xyz
- Infrastructure questions, or permanent deletion of your data (your whole account or one service): infrastructure@clatterlabs.xyz
We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Related articles
Still need help?
Tried the steps above and still stuck? Email us. We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Infrastructure questions, or permanent deletion of your data
infrastructure@clatterlabs.xyzFor deleting your whole account or the data of one service.