Loading...
const res = await llm.generate({ prompt, max_tokens: 200 });
const data = JSON.parse(res.text);const res = await llm.generate({ prompt, max_tokens: 2000 });
if (res.stopReason === 'max_tokens') {
throw new Error('Response was cut off by the token limit');
}
const data = JSON.parse(res.text);Checking the stop reason catches truncated output before JSON.parse fails on missing closing brackets.
Usually no. It caps only the generated output, but the prompt plus the output must still fit in the context window.
No. It is only a ceiling, and the model stops when it is done. Ask for the length you want in the prompt.
Normally no. Billing counts the tokens actually generated, not the limit you set.