Skip to content

fix(#230): forward the per-job NIM API key for TXT/SRT/DOCX - #276

Open
atirna wants to merge 1 commit into
hydropix:mainfrom
atirna:fix/forward-per-job-nim-api-key
Open

atirna wants to merge 1 commit into
hydropix:mainfrom
atirna:fix/forward-per-job-nim-api-key

Conversation

@atirna

@atirna atirna commented Sep 7, 2026

Copy link
Copy Markdown

Problem

A NIM API key entered per job in the web UI only works for EPUB jobs. TXT, SRT and DOCX jobs silently drop it: with no NIM key in .env, the provider factory falls back to the empty .env value and the job fails even though a valid key was provided (#230).

Root cause

translate_file() forwards the per-job provider keys on the EPUB path only:

  • the TXT/SRT adapter path builds llm_config without nim_api_key (src/core/adapters/translate_file.py:335-344)
  • the DOCX path calls create_llm_provider() without it (src/core/adapters/translate_file.py:263-273)

The factory's nim branch (src/core/llm/factory.py:164-169) reads the kwarg before its env fallback, so the key never arrives and _require_key raises "NVIDIA NIM provider requires an API key". For TXT/SRT this surfaces mid-run as a failed unit (the job ends partial); for DOCX it raises at provider creation.

Fix

Thread nim_api_key at both call sites, matching the EPUB path. Two one-line kwargs; nothing else changes.

I also audited the sibling per-job keys (gemini, openai, openrouter, mistral, deepseek, poe) at both call sites, all are already forwarded; NIM was the only omission, at both sites.

How to reproduce (before the fix)

  1. Start a job with provider nim, a per-job NIM API key filled in the web UI, and no NIM_API_KEY in .env.
  2. TXT/SRT: every unit fails with "NVIDIA NIM provider requires an API key", the job ends partial, the output file is untranslated. DOCX: the job errors immediately at provider creation.
  3. After this fix both formats translate and complete.

Testing

New tests/unit/test_translate_file_per_job_keys.py drives the real translate_file() entry point per format (txt, srt, docx) with llm_provider='nim', a per-job key and NIM_API_KEY absent; the real factory runs (its _require_key gate is the oracle), only the network boundary (provider.generate) is stubbed. All four tests fail on the old code (TXT/SRT: job ends partial; DOCX: the exact factory ValueError) and pass with the fix.

.venv/bin/python -m pytest tests/unit/test_translate_file_per_job_keys.py   # 4 passed
.venv/bin/python -m pytest tests/unit                                      # 1765 passed, 1 failed (pre-existing), 1 skipped

The single failure (test_path_validator.py::test_reject_path_separator_backslash) also fails on the clean base commit 0a26cec: it assumes \ is a path separator, which it is not on macOS/Linux. Unrelated to this change.

Changes

  • src/core/adapters/translate_file.py: add nim_api_key to the DOCX create_llm_provider call and to the TXT/SRT llm_config
  • tests/unit/test_translate_file_per_job_keys.py: regression tests (new file)

Closes #230

translate_file() forwarded per-job provider keys on the EPUB path only.
The TXT/SRT adapter path's llm_config and the DOCX create_llm_provider
call omitted nim_api_key, so with llm_provider='nim', a per-job NIM key
and no NIM key in .env, the factory fell back to the empty env value:
TXT/SRT jobs failed mid-run with 'NIM provider requires an API key'
(the key silently dropped) and DOCX jobs raised at provider creation.

Thread nim_api_key at both call sites, matching the EPUB path. The
sibling per-job keys were audited and are already forwarded at both
sites. Regression tests drive the real translate_file() entry point per
format with the real factory; only the network boundary is stubbed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-job NIM API key silently dropped for TXT/SRT/DOCX (EPUB-only forwarding)

1 participant