OpenProgram Docs

Credential connection

CredentialData stored in the pool ResolvedConnection external file and helper already read Wire falls back to model.base_url
  1. CredentialData, stored in the pool
  2. resolve_connection reads the external file or runs the helper
  3. ResolvedConnection
  4. Wire: model.base_url only when the credential has none

Never reduced to a bare key string. OAuth comes from kind, not a token prefix. One key can reach another endpoint: a Bailian key stores https://…maas.aliyuncs.com/compatible-mode/v1, under the same openai-completions protocol, with no extra model list.

CredentialData

kindauth_valuedata
api_keythe keyusually empty
oauthaccess tokenrefresh_token expires_at_ms client_id token_endpoint scope id_token
device_codeaccess tokenrefresh_token expires_at_ms device_code_flow_id
cli_delegatedemptystore_path access_key_path refresh_key_path expires_key_path
credential_processemptycommand parses json_key_path cache_seconds
ssoemptybroker subject

Every kind also has base_url and headers, both empty by default. Email, display name and org id stay in Credential.metadata.

resolve_connection

KindBehaviour
cli_delegatedReads the external file; that CLI stays authoritative
credential_processRuns the helper, reuses its token for cache_seconds. Failure raises AuthCredentialProcessError, re-raised by the resolver ladder and never replaced by another layer.
ssoRaises AuthConfigError: reserved, no flow implements it
othersReturns auth_value

auth.usage.acquire_pooled returns (conn, profile, cred_id).

Wire rules

api_key  = conn.auth_value if conn else opts.api_key
base_url = (conn.base_url if conn and conn.base_url else None) or model.base_url
headers  = {**(model.headers or {}), **(conn.headers if conn else {}), **(opts.headers or {})}
is_oauth = bool(conn and conn.kind in ("oauth", "device_code"))

Same in openai_completions, openai_responses and anthropic.

Old format and carry-over

Runtime accepts only the current structure; old JSON with __type__ is an error. auth/carry_over.py runs once before the store first reads: it rewrites every payload of every old ~/.openprogram/auth/<provider>/<account>.json into one list per provider, auth/<provider>/credentials.json, after copying the folder aside. No new login.

Old __type__New kindauth_value from
ApiKeyPayloadapi_keyapi_key
OAuthPayloadoauthaccess_token
DeviceCodePayloaddevice_codeaccess_token
CliDelegatedPayloadcli_delegatedempty
ExternalProcessPayloadcredential_processempty
SsoPayloadssoempty

Other fields move to data.

Tests
  • resolve_connection: each kind; key with and without base_url; live external read; helper json and text parsing, cache window, every failure raising; sso raising.
  • Round trip of CredentialData, including data.
  • Wire rules: credential base_url wins; kind=oauth sets is_oauth with no prefix.
  • End to end: a Bailian-base_url key reaches Bailian; the official OpenAI key stays on its default.
  • Carry-over: correct fields, no __type__, every credential arrives, a second run changes nothing.

Auth storage

Last updated · 2026-11-25