Skip to content

API Reference parrot.handlers.studio.key_source

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.handlers.studio.key_source

View source

Which key serves an LLM call: the server's own or the caller's stored personal (BYOK) one (PA-2).

credentials_for feeds the per-request llm-clients catalogue; :func:choose_key_source is the single decision test/ask and the assistant share: one source available -> it is used; both -> the caller must say which (409 key_source_required); an explicit source that does not exist -> 422 key_source_unavailable. Neither key material nor environment-variable names ever leave this module.

Attribute AMBIENT_PROVIDERS

Alias AbstractClient

Re-exported from parrot.clients.base.AbstractClient.

Alias DocumentDb

Re-exported from parrot.interfaces.documentdb.DocumentDb.

Attribute KEY_SOURCES

Attribute KeySource

Class KeySourceRefusal

A refusal to pick a key: status/code/message plus structured details for the response.

Parameter Type Default Description
status int
code str
message str
details dict[str, Any] | None None

Alias LLMFactory

Re-exported from parrot.clients.factory.LLMFactory.

Attribute STUDIO_CATALOG_USABLE_ONLY

Host opt-in (app[STUDIO_CATALOG_USABLE_ONLY] = True): /catalog/llm-clients hides rows with no usable credential unless ?usable=0 is sent. Off (default) every row is returned, as before PA-3.

Attribute STUDIO_KEY_SOURCE_CHOICE

Host opt-in (app[STUDIO_KEY_SOURCE_CHOICE] = True): with BOTH a server and a personal key and no explicit key_source the call is refused (409 key_source_required) instead of silently using the personal key.

Function choose_key_source

The key source of one call, or raise :class:KeySourceRefusal.

choose_key_source(provider: str, *, has_byok: bool, requested: str | None = None, use_byok: bool = True, ask_when_both: bool = False) -> KeySource

Parameter Type Default Description
provider str LLM provider key.
has_byok bool The caller has a stored personal key for provider.
requested str | None None Explicit key_source of the request (None = not given).
use_byok bool True Legacy opt-out; False with no explicit source means the server key (never asks).
ask_when_both bool False The host opted in to :data:STUDIO_KEY_SOURCE_CHOICE: both keys and no explicit source raise 409. Off (default) the personal key wins silently, as before PA-2.

Returns: KeySource

Function credentials_for

The credentials of a catalogue row: byok first-class when the caller has a key, server if any.

credentials_for(provider: str, byok_providers: frozenset[str]) -> list[KeySource]

Parameter Type Default Description
provider str
byok_providers frozenset[str]

Returns: list[KeySource]

Function key_source_choice_enabled

Whether the host opted in to :data:STUDIO_KEY_SOURCE_CHOICE (default off: the previous behaviour).

key_source_choice_enabled(app: Any) -> bool

Parameter Type Default Description
app Any

Returns: bool

Attribute logger

Function server_credential_state

Whether the SERVER holds a credential for provider; unknown when the client cannot say.

Evaluated on every call (navconfig is read live): a key added to or removed from the environment changes the answer without a restart.

server_credential_state(provider: str) -> Literal['present', 'absent', 'unknown']

Parameter Type Default Description
provider str

Returns: Literal['present', 'absent', 'unknown']

Function user_byok_providers

Providers the user has a stored key for (no decryption). Fails closed: an unreadable store is "none".

user_byok_providers(app: Any, user_id: Any) -> frozenset[str]

Parameter Type Default Description
app Any
user_id Any

Returns: frozenset[str]

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally