Skip to content

feat: per-call API key provider for multi-tenant embedders (v1.2.0) - #126

Merged
rbuchmayer-pplx merged 1 commit into
perplexityai:mainfrom
rbuchmayer-pplx:feat-api-key-provider
Jul 27, 2026
Merged

feat: per-call API key provider for multi-tenant embedders (v1.2.0)#126
rbuchmayer-pplx merged 1 commit into
perplexityai:mainfrom
rbuchmayer-pplx:feat-api-key-provider

Conversation

@rbuchmayer-pplx

Copy link
Copy Markdown
Collaborator

The library entry point added in 1.1.0 still resolved the API key from a module-level env read, so an embedder hosting the server for more than one key (one server instance per request, each with its own credentials) had no way to route the right key per call.

  • createPerplexityServer(serviceOrigin?, { apiKey?: () => string | undefined }): an optional per-call key provider, threaded through every upstream call including the fire-and-forget server-side cancel
  • A configured provider fully replaces the env var: returning no key fails the call with a structured error instead of silently falling back to the process-wide key
  • No provider = existing env var behavior, unchanged; stdio bin and standalone HTTP mode untouched
  • README section for library usage

Design note: we considered resolving keys from the SDK's per-request extra.authInfo instead. The provider option keeps the standalone server single-tenant by default (inbound bearer headers are never interpreted as upstream credentials) and leaves auth policy to the embedder; hosts that use SDK auth middleware can bridge it in their provider closure.

Tests: provider key used end to end through a real client (env ignored), provider-returns-no-key fails without touching the network, cancel path carries the provider key. Suite at 89.

Note: merging publishes 1.2.0 (the publish workflow triggers on package.json changes).

@rbuchmayer-pplx
rbuchmayer-pplx marked this pull request as ready for review July 27, 2026 19:39
The API key was a module-level env read baked into every upstream call,
so an embedder hosting the server for more than one key had no way to
route each request's own credentials. createPerplexityServer now accepts
{ apiKey: () => string | undefined }, threaded through every upstream
call including the server-side cancel path. A configured provider fully
replaces the env var: returning no key fails the call rather than
silently billing the process-wide key.
@rbuchmayer-pplx
rbuchmayer-pplx force-pushed the feat-api-key-provider branch from ab354f6 to d19120b Compare July 27, 2026 19:41
@rbuchmayer-pplx
rbuchmayer-pplx merged commit 9f7dd0b into perplexityai:main Jul 27, 2026
2 checks passed
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.

1 participant