Lingarr version
1.2.4
Describe the problem
When using batch translation with the Anthropic provider, any batch large enough to produce more than ~1024 output tokens fails with:
Anthropic response contained no tool_use block (stop_reason: max_tokens).
The HTTP request itself succeeds (status 200), but the model's response is truncated because the output token limit is reached before the structured result is complete. Since the batch path forces a tool call (tool_choice → record_translation_batch) and expects all translations inside a single tool_use block, a truncated response has no usable/complete tool_use block, and the job fails.
Root Cuase
In Lingarr.Server/Services/Translation/AnthropicService.cs, method TranslateBatchWithAnthropicApi, the request body hardcodes the output limit:
var requestBody = new Dictionary<string, object>
{
["model"] = _model!,
["max_tokens"] = 1024, // hardcoded
["system"] = _prompt!,
["tools"] = new[] { ... record_translation_batch ... },
["tool_choice"] = new { type = "tool", name = "record_translation_batch" },
["messages"] = new[] { new { role = "user", content = JsonSerializer.Serialize(subtitleBatch) } }
};
Fix
max_token should be taken from RequestTemplate
Screenshots or Additional Context
No response
Human written confirmation
Lingarr version
1.2.4
Describe the problem
When using batch translation with the Anthropic provider, any batch large enough to produce more than ~1024 output tokens fails with:
Anthropic response contained no tool_use block (stop_reason: max_tokens).The HTTP request itself succeeds (status 200), but the model's response is truncated because the output token limit is reached before the structured result is complete. Since the batch path forces a tool call (tool_choice → record_translation_batch) and expects all translations inside a single tool_use block, a truncated response has no usable/complete tool_use block, and the job fails.
Root Cuase
In Lingarr.Server/Services/Translation/AnthropicService.cs, method TranslateBatchWithAnthropicApi, the request body hardcodes the output limit:
var requestBody = new Dictionary<string, object>
{
["model"] = _model!,
["max_tokens"] = 1024, // hardcoded
["system"] = _prompt!,
["tools"] = new[] { ... record_translation_batch ... },
["tool_choice"] = new { type = "tool", name = "record_translation_batch" },
["messages"] = new[] { new { role = "user", content = JsonSerializer.Serialize(subtitleBatch) } }
};
Fix
max_tokenshould be taken fromRequestTemplateScreenshots or Additional Context
No response
Human written confirmation