feat: support authenticated OpenAI-compatible embedding endpoints - #209
Conversation
Allow the OpenAI embedding dialect to use bearer credentials from the environment and an optional provider-specific endpoint path. Keep native Ollama unauthenticated and preserve the existing /v1/embeddings behavior when no custom endpoint path is configured.
|
Thank you — this is careful work and most of it is exactly right. I'm holding the merge on one thing, and it's a gap in the threat model rather than a mistake in what you built. The key can still reach a log, on the error path. If a provider rejects the request with a 4xx whose body contains the key — That warning is the part I'd point at: it already logs
What I'd like before merging: redact the credential on the error path — wherever a response body is carried into an exception on a request that had an Everything else stands and I don't want it lost in the hold. Scoping the header structurally — Two smaller things for the same push, neither a condition: Push onto the same branch and I'll review and merge once checks are green. |
Sanitize authenticated provider response bodies before carrying them into embedding exceptions, add a regression test through EmbeddingUnavailable, and document the embedding credential variables.
|
@Paul-Kyle Thanks for catching this. I pushed a follow-up that redacts the credential from authenticated provider response bodies before they are carried into exceptions, including the 4xx and deterministic 5xx paths. I also added a stub-transport regression test that drives a 401 response echoing the key through the embedder wrapper and verifies the key is absent from both the logs and the raised EmbeddingUnavailable. For the _FILE behavior, the per-request resolution is intentional so file-backed credentials can be rotated without requiring a restart. All checks are green now. |
|
Merged — thank you for addressing the redaction gap and adding the regression test. Two details worth naming. You redact before truncating to 300 characters; the other order looks identical in review and leaves a key fragment whenever the credential straddles the boundary. And your regression drives a credential-bearing 401 through the embedder wrapper rather than the client, then asserts On per-request resolution of One limitation for the record, not a request: redaction matches the credential as a literal string, so a provider that echoes it re-encoded or partially masked would slip through. That is the right tradeoff for the failure we actually have, and worth knowing before anyone treats it as a guarantee. |
Summary
Adds bearer authentication and configurable endpoint paths for hosted
OpenAI-compatible embedding providers.
The existing OpenAI-compatible embedding path assumes
/v1/embeddingsand had no way to provide credentials, which prevents providers with a
different API root or bearer-auth requirement from being used.
Changes
PALINODE_EMBEDDING_API_KEYorPALINODE_EMBEDDING_API_KEY_FILEAuthorization: Beareronly for theopenaiembedding dialectembeddings.primary.endpoint_path/v1behavior whenendpoint_pathis not configured_FILEloading, endpoint paths, Ollama isolation,and secret logging
I used an optional
endpoint_pathso existing configurations continue tobehave as before, while hosted providers can treat
urlas the provider rootand append their provider-specific embedding path.
Native Ollama never receives the embedding API key.
Testing
pytest tests/test_embed_openai_dialect.py -v --tb=shortpytest tests/test_api_bearer_auth.py -v --tb=shortpytest -qruff check palinode/ tests/ scripts/bandit -r palinode/ -llgit diff --checkCloses #203