Synth 2.5 Context Window: Long Conversations, Token Budgets and the 502 You Shouldn't Retry
Every chat feature eventually meets a conversation that is too long for the model. On Synth 2.5 that limit is 32,000 tokens per request, and hitting it produces an error that looks temporary but isn't. This is how to budget the window, trim and summarize history, and handle the overflow when it happens anyway.
Short answer: both Synth 2.5 models are served with a 32,000-token window that must hold the system prompt, history, new message and reply. The gateway doesn't check length, so an oversized request comes back as 502 server_error with the model server's message, and retrying it never works. Budget about 23,000 tokens for verbatim history, drop whole user/assistant pairs from the oldest end, fold them into a short rolling summary written by synth-2.5-flash, and treat a context-length 502 as “trim and resend once”, not “retry”.
What the 32,000 tokens have to hold
The LuciditySH Platform serves synth-2.5-pro and synth-2.5-flash with a 32,000-token context window each. The base architectures support more (the published configs list 262,144 positions for Pro and 131,072 for Flash), but the window you get through the API is the served one, 32,000.
That window is shared by everything in one request. A budget that works for a chat feature with a moderate system prompt:
| Part of the request | Tokens | Note |
|---|---|---|
| System prompt | 1,500 | Paid on every call; keep it tight. |
| Rolling summary of older turns | 800 | Replaces everything you dropped. |
| Current user message | 500 | Cap user input in your UI. |
| Reply reserve (max_tokens) | 1,000 | Some model servers count it against the window. |
| Safety margin, 15% | 4,800 | Covers estimate error and the Pro/Flash tokenizer difference. |
| Recent turns, verbatim | 23,400 | What is left. |
Two details make the margin necessary rather than cautious. First, the two models count differently: Pro is built on Gemma 4 and uses its tokenizer, while Flash is built on Ling 3 Tiny with a different vocabulary. A request for Pro that falls back to Flash is the same text measured by a different tokenizer. Second, whether max_tokens counts against the window depends on the model server, and some reject a request whose prompt plus max_tokens exceeds it. Reserving the reply up front avoids both problems.
What happens when a request is too long
This is the part most integrations get wrong, because the error doesn't say “your request is too long” in a way your retry logic recognizes:
- The gateway forwards it. The platform validates the model, your key and your balance, but not request length. The request reaches the model server, which rejects it.
- You get a 502. Any non-200 from the model server becomes HTTP 502 with
type: "server_error". Themessageis the model server's own text, and its exact wording depends on the server. - Fallback runs first. A request for
synth-2.5-prois retried onsynth-2.5-flashbefore the error comes back. Flash has the same window, so it fails too, and the error you see is Flash's. - It costs a Pro slot, not money. Failed attempts aren't billed. But the attempt on Pro still used one of Pro's 5 requests per minute, a limit shared by every caller of the model.
- Streaming is the same. The error arrives as a normal JSON response before any bytes stream.
Our production guide says to retry 500 and 502 with backoff, which is right for transient upstream failures. A context-length 502 is the exception: the same request fails identically every time, so a retry loop burns Pro capacity and delays the user for nothing.
Counting tokens before you send
You need a size estimate before each call. Three sources, from most to least exact:
- The previous response.
usage.prompt_tokensis the measured size of the last request whenusage.estimatedisfalse. Last prompt plus last reply plus the new message is a close estimate of the next request. Note it was measured by whichever model answered; checkmodel. - The model's own tokenizer. Both tokenizers are in the Hugging Face repos. Exact, but you need one per model, and Flash's repo ships custom code you should review before running it.
- Characters divided by three. The rule the platform itself uses when the model server reports no counts. English averages closer to four characters per token, so this over-counts slightly, which is the safe direction. It under-counts for Chinese or Japanese text, where a token can be one or two characters; use a tokenizer there.
The code below uses the third, with the margin from the budget table. Swap in the first when you have it.
Trim by whole exchanges
Keep the system prompt and the newest turns, and drop from the oldest end. Drop a user message and its reply together. A history that starts with an orphaned assistant turn confuses the model about who said what, and a creative-writing model like Synth is more likely to continue in the wrong voice when the turn structure is broken.
const WINDOW = 32_000 // tokens per request, both Synth 2.5 models
const REPLY = 1_000 // the max_tokens you send
const MARGIN = 0.15 // estimates are rough; keep 15% spare
const est = (s) => Math.ceil(s.length / 3) + 4 // ~3 chars per token, +4 per message
// turns alternate user / assistant, oldest first
export function fitHistory(system, summary, turns, userMsg) {
const budget = Math.floor(WINDOW * (1 - MARGIN)) - REPLY
let used = est(system) + est(summary) + est(userMsg)
let start = turns.length
// walk back one user+assistant pair at a time, so history never starts mid-exchange
while (start >= 2) {
const pair = est(turns[start - 2].content) + est(turns[start - 1].content)
if (used + pair > budget) break
used += pair
start -= 2
}
return { kept: turns.slice(start), dropped: turns.slice(0, start), used }
}Pin anything that must never be dropped, such as the user's stated requirements or a document they uploaded, by moving it into the system prompt or the summary rather than leaving it in the history.
Rolling summaries on Flash
Dropped turns don't have to be forgotten. Fold them into a short set of notes that travels with every request, and update the notes each time more turns drop off. Run the summary on synth-2.5-flash: it costs 30% of Pro on input, and it doesn't take slots from Pro's shared limit.
const BASE = 'https://platform.lucidity.sh/v1'
const SUMMARY_PROMPT = `Update the running notes for this conversation.
Keep: names, decisions, facts the user gave, open questions, promises made.
Drop: greetings, repetition, wording. Plain sentences, under 250 words.`
export async function summarize(oldSummary, dropped) {
const transcript = dropped.map((t) => `${t.role}: ${t.content}`).join('\n')
const res = await fetch(`${BASE}/chat/completions`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.LUCIDITY_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'synth-2.5-flash', // cheap, and outside Pro's shared 5 RPM limit
temperature: 0.3, // recall, not variety
max_tokens: 400,
messages: [
{ role: 'system', content: SUMMARY_PROMPT },
{ role: 'user', content: `Notes so far:\n${oldSummary || '(none)'}\n\nNew turns:\n${transcript}` },
],
}),
})
if (!res.ok) return oldSummary // keep the old notes; never block the chat on a summary
const data = await res.json()
return data.choices[0].message.content.trim()
}- Ask for plain notes, not a schema. Flash's model card says it can't follow prompts that require heavy, specific formatting. Short plain sentences are what it does reliably.
- Lower temperature than the card's 0.8 to 1. That range is for creative output. For notes you want recall, so the example uses 0.3; test it on your own transcripts.
- Summarize early, in batches. Start when history passes about 70% of its budget and fold in several exchanges at once. One summary call per turn doubles your request count for little gain.
- Don't block on it. If the summary call fails, keep the old notes and answer the user. Run it after the reply if latency matters.
Input dominates chat cost, so long history is expensive history. Input cost of one turn by history size:
| Input tokens per turn | Synth 2.5 Pro | Synth 2.5 Flash |
|---|---|---|
| 4,000 | $0.0004 | $0.00012 |
| 12,000 | $0.0012 | $0.00036 |
| 28,000 | $0.0028 | $0.00084 |
Summarizing 12,000 tokens of old turns into about 700 on Flash costs about $0.0004. Every later Pro turn then sends about 11,300 fewer input tokens, saving about $0.0011 per turn. The summary pays for itself on the next turn. If you bill customers per use, the per-customer cost tracking guide shows where these numbers go.
Handling the overflow error
Estimates will occasionally be wrong, so handle the overflow explicitly. Match the message loosely, because its wording comes from the model server, and only treat it as an overflow on a 502:
// The gateway does not check the window. The model server rejects the request,
// and you get 502 server_error with the server's own message.
function isContextOverflow(status, body) {
if (status !== 502) return false
const msg = String(body?.error?.message ?? '').toLowerCase()
return /context|too long|maximum.*token|exceed/.test(msg)
}
async function send(conv, userMsg, budgetScale = 1) {
const res = await callSynth(conv, userMsg, budgetScale) // builds messages with fitHistory
const body = await res.json()
if (res.ok) return body
if (isContextOverflow(res.status, body) && budgetScale === 1) {
return send(conv, userMsg, 0.6) // trim harder, resend once
}
throw Object.assign(new Error(body?.error?.message), { status: res.status })
}- Resend once, smaller. If the second attempt also overflows, the problem is a single message that is too big, not the history. Tell the user, or split the input.
- Log it. Overflows mean your estimate or your budget is off. Count them per feature and adjust the margin.
- Cap input in the UI. A paste box that accepts 200,000 characters will produce requests no trimming can fix. About 1,500 characters per 500 tokens is a reasonable cap to show the user.
Documents longer than the window
For B2B jobs like summarizing a long contract, call transcript or support thread, trimming is the wrong tool; you need every part of the document. Split it instead:
- Split at paragraph or section boundaries into chunks of about 6,000 to 8,000 tokens.
- Summarize or extract from each chunk with
synth-2.5-flash. Send these calls to Flash directly: Pro's 5 requests per minute are shared by all callers, so a batch of chunk calls on Pro would mostly fall back to Flash anyway, after waiting. - Combine the chunk results in one final call, on Pro if the quality of the final text matters.
Queue the chunk calls instead of firing them all at once, and keep each chunk's result so a failure in chunk 9 doesn't mean redoing chunks 1 to 8. If you call Synth through LangChain or LiteLLM, the same limits apply; see the framework setup guide for batch settings.
Synth 2.5 context window FAQ
What is the context window of Synth 2.5 on LuciditySH Platform?
Both Synth 2.5 Pro and Synth 2.5 Flash are served with a 32,000-token window per request. The window has to hold the system prompt, the conversation history, the new message and the reply, so plan on about 23,000 tokens of verbatim history once you reserve room for the rest.
What happens if a request is longer than the context window?
The platform gateway does not check request length against the window. The request reaches the model server, which rejects it, and the API returns HTTP 502 with type server_error and the model server's message. A request for synth-2.5-pro also falls back to synth-2.5-flash first, which has the same window and fails the same way. Failed attempts are not billed.
Should I retry a 502 from the Synth API?
Retry a 502 with backoff only when it is a transient upstream failure. If the error message mentions the context length or too many tokens, retrying the same request fails every time. Trim the history and resend once instead.
How do I count tokens for Synth 2.5 before sending a request?
Use the usage.prompt_tokens of the previous response as the exact size of the conversation so far, when usage.estimated is false, and add a rough estimate for the new message. For a pre-send estimate, about three characters per token over-counts English text slightly, which is the safe direction. Pro and Flash use different tokenizers, so leave a margin.
Is it cheaper to summarize old turns than to keep them?
Usually yes. Summarizing 12,000 tokens of old turns into about 700 on Synth 2.5 Flash costs about $0.0004. Each later Synth 2.5 Pro turn then sends about 11,300 fewer input tokens, which saves about $0.0011 per turn, so the summary pays for itself on the next turn.
Sources
- Synth 2.5 Pro Preview model card and config (Gemma 4 base, tokenizer, sampling settings)
- Synth 2.5 Flash Preview model card and config (Ling 3 Tiny base, formatting limitation)
- OpenAI Chat Completions API reference (the request and usage shapes the platform follows)
- LuciditySH Platform docs: errors, automatic fallback and rate limits (in the dashboard after sign-in)
Create an account and get an API key for Synth 2.5 Pro and Flash. Prepaid, per token, no monthly fee.
Create an account