LLM Provider Key Client¶
The LLM Provider Key client provides methods for managing LLM provider API keys in the Opik platform.
- class opik.rest_api.llm_provider_key.client.LlmProviderKeyClient(*, client_wrapper: SyncClientWrapper)¶
Bases:
object- delete_llm_provider_api_keys_batch(*, ids: Sequence[str], request_options: RequestOptions | None = None) None¶
Delete LLM Provider’s ApiKeys batch
- Parameters:
ids (Sequence[str])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Return type:
None
- find_llm_provider_keys(*, request_options: RequestOptions | None = None) ProviderApiKeyPagePublic¶
Find LLM Provider’s ApiKeys
- Parameters:
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
LLMProviderApiKey resource
- Return type:
- store_llm_provider_api_key(*, provider: Literal['openai', 'anthropic', 'gemini', 'openrouter', 'vertex-ai', 'bedrock', 'ollama', 'custom-llm', 'opik-free'] | Any, api_key: str | None = OMIT, name: str | None = OMIT, provider_name: str | None = OMIT, headers: Dict[str, str] | None = OMIT, configuration: Dict[str, str] | None = OMIT, base_url: str | None = OMIT, auth_config: ProviderAuthConfigWrite | None = OMIT, request_options: RequestOptions | None = None) None¶
Store LLM Provider’s ApiKey
- Parameters:
provider (ProviderApiKeyWriteProvider)
api_key (Optional[str])
name (Optional[str])
provider_name (Optional[str]) – Provider name - required for custom LLM and Bedrock providers to uniquely identify them (e.g., ‘ollama’, ‘vllm’, ‘Bedrock us-east-1’). Must not be blank for custom and Bedrock providers. Should not be set for standard providers (OpenAI, Anthropic, etc.). This requirement is conditional and validation is enforced programmatically.
headers (Optional[Dict[str, str]])
configuration (Optional[Dict[str, str]])
base_url (Optional[str])
auth_config (Optional[ProviderAuthConfigWrite])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Return type:
None
- get_llm_provider_api_key_by_id(id: str, *, request_options: RequestOptions | None = None) ProviderApiKeyPublic¶
Get LLM Provider’s ApiKey by id
- Parameters:
id (str)
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
LLMProviderApiKey resource
- Return type:
- update_llm_provider_api_key(id: str, *, api_key: str | None = OMIT, name: str | None = OMIT, provider_name: str | None = OMIT, headers: Dict[str, str] | None = OMIT, configuration: Dict[str, str] | None = OMIT, base_url: str | None = OMIT, auth_config: ProviderAuthConfig | None = OMIT, request_options: RequestOptions | None = None) None¶
Update LLM Provider’s ApiKey. api_key and auth_config are mutually exclusive: setting a valid auth_config on a provider that holds a static api_key clears the stored key; send auth_config as an empty object to clear the recipe and switch back to a static key
- Parameters:
id (str)
api_key (Optional[str])
name (Optional[str])
provider_name (Optional[str]) – Provider name - can be set to migrate legacy custom LLM or Bedrock providers to the new multi-provider format. Once set, it cannot be changed. Should only be set for custom LLM and Bedrock providers.
headers (Optional[Dict[str, str]])
configuration (Optional[Dict[str, str]])
base_url (Optional[str])
auth_config (Optional[ProviderAuthConfig])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Return type:
None
- test_llm_provider_auth_config(*, provider_id: str | None = OMIT, auth_config: ProviderAuthConfig | None = OMIT, request_options: RequestOptions | None = None) Result¶
Runs the token fetch once, backend-side, and reports the token lifetime. The token itself is never returned. Send provider_id to test the stored config, auth_config to test submitted values, or both to resolve secret sentinels against the stored config.
- Parameters:
provider_id (Optional[str]) – Test the stored auth config of this provider; also the sentinel-resolution target when auth_config is sent
auth_config (Optional[ProviderAuthConfig])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
Token fetched
- Return type:
Usage Example¶
import opik
client = opik.Opik()
# Create or update a provider API key
client.rest_client.llm_provider_key.create_or_update_provider_api_key(
provider="openai",
api_key="your-api-key"
)
# List provider API keys
keys = client.rest_client.llm_provider_key.get_provider_api_keys(
page=0,
size=10
)
# Delete a provider API key
client.rest_client.llm_provider_key.delete_provider_api_key(
provider="openai"
)