Skip to content

[BUG] Anthropic batch translation always fails for larger batches — max_tokens is hardcoded to 1024 #444

Description

@WojtekK78

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

  • I confirm this issue was written by me and not generated by an LLM or AI assistant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions