feat(extractor): optional bearer token for the HTTP extraction transport - #573
feat(extractor): optional bearer token for the HTTP extraction transport#573sedmondson wants to merge 1 commit into
Conversation
Add LCG_EXTRACTION_API_KEY, sent as Authorization: Bearer <key> on --extractor-http / LCG_EXTRACTION_URL. Mirrors LCG_EMBEDDING_API_KEY on the embedder side, so an authenticated OpenAI-compatible proxy (a corporate LLM gateway, a hosted provider) can serve extraction when no direct ANTHROPIC_API_KEY is available. Never applied to the UDS transport. Adds with_api_key() for explicit control and two tests via a header-capturing stub server. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
There was a problem hiding this comment.
Reviewed the addition of LCG_EXTRACTION_API_KEY / with_api_key to OaiExtractor (crates/core/src/extractor.rs), its wiring in from_env/new_http/new_uds, the two new header-capturing unit tests, and the docs/configuration.md entry. Traced how the key flows through send_chat's HTTP branch (bearer_auth), confirmed the UDS transport unconditionally forces api_key: None (including when with_api_key is called on a UDS-backed instance), and checked that cassette recording (RecordingExtractor) operates at the Extractor-trait level and never captures raw HTTP headers, so the token can't leak into recorded cassettes or stderr logging in crates/service/src/main.rs. Empty-string keys are filtered consistently at both the env-read and builder call sites. The change is small, mirrors the existing embedder pattern closely, and is well covered by tests. No bugs, security issues, or design problems found.
Summary
Adds an optional bearer token to the OpenAI-compatible HTTP extraction transport (
--extractor-http/LCG_EXTRACTION_URL), read from a newLCG_EXTRACTION_API_KEYenv var and sent asAuthorization: Bearer <key>.This mirrors what the embedder already supports via
LCG_EMBEDDING_API_KEY, and closes the gap for users who can only reach a frontier model through an authenticated OpenAI-compatible proxy (a corporate LLM gateway, a hosted provider, etc.) rather than a directANTHROPIC_API_KEY. Without this,--extractor-httpcould only target unauthenticated local servers.Changes
OaiExtractorgains anapi_key: Option<String>field, populated fromLCG_EXTRACTION_API_KEYinnew_http/from_env. AlwaysNonefor the UDS transport, matching the embedder's rule that a local socket never gets a credential.send_chatadds.bearer_auth(key)on the HTTP path when a key is present. No behavior change when unset.with_api_key(Option<String>)builder for explicit control (and to keep tests independent of the ambient environment).docs/configuration.md: one row forLCG_EXTRACTION_API_KEY.Verified
cargo fmt --all,cargo clippy -p lcg-core -- -D warnings, new tests pass.knowledge_process_chunkon a short paragraph extracted 7 entities / 7 edges, and the gateway's ```json-fenced responses were recovered by the existing fence handling.Notes
--extractor-api-keyif you'd prefer symmetry with the flags.🤖 Generated with Claude Code