pub struct PortkeyConfig { /* private fields */ }Expand description
Configuration for the Portkey API client.
This struct holds all the necessary configuration parameters for creating and using a Portkey API client, including authentication credentials, API endpoint information, and HTTP client settings.
§Examples
Creating a config with virtual key:
use portkey_sdk::PortkeyConfig;
use portkey_sdk::builder::AuthMethod;
let config = PortkeyConfig::builder()
.with_api_key("your-portkey-api-key")
.with_auth_method(AuthMethod::virtual_key("your-virtual-key"))
.build()
.unwrap();Creating a config with provider auth:
use portkey_sdk::PortkeyConfig;
use portkey_sdk::builder::AuthMethod;
let config = PortkeyConfig::builder()
.with_api_key("your-portkey-api-key")
.with_auth_method(AuthMethod::provider_auth("openai", "Bearer sk-..."))
.build()
.unwrap();Creating a config from environment:
// Requires PORTKEY_API_KEY and PORTKEY_VIRTUAL_KEY environment variables
let config = PortkeyConfig::from_env().unwrap();Implementations§
Source§impl PortkeyConfig
impl PortkeyConfig
Sourcepub fn builder() -> PortkeyBuilder
pub fn builder() -> PortkeyBuilder
Creates a new configuration builder.
This is the recommended way to construct a PortkeyConfig.
§Examples
let config = PortkeyConfig::builder()
.with_api_key("your-api-key")
.build()
.unwrap();Sourcepub fn build_client(self) -> Result<PortkeyClient>
pub fn build_client(self) -> Result<PortkeyClient>
Creates a new Portkey API client using this configuration.
§Examples
let config = PortkeyConfig::builder()
.with_api_key("your-api-key")
.build()
.unwrap();
let client = config.build_client().unwrap();Sourcepub fn masked_api_key(&self) -> String
pub fn masked_api_key(&self) -> String
Returns a masked version of the API key for safe display/logging.
Shows the first 4 characters followed by “”, or just “” if the key is shorter than 4 characters.
Sourcepub fn auth_method(&self) -> &AuthMethod
pub fn auth_method(&self) -> &AuthMethod
Returns the authentication method.
Sourcepub fn cache_namespace(&self) -> Option<&str>
pub fn cache_namespace(&self) -> Option<&str>
Returns the cache namespace, if set.
Sourcepub fn cache_force_refresh(&self) -> Option<bool>
pub fn cache_force_refresh(&self) -> Option<bool>
Returns the cache force refresh flag, if set.
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Creates a configuration from environment variables.
§Environment Variables
Required:
PORTKEY_API_KEY- Your Portkey API key
Authentication (choose one):
PORTKEY_VIRTUAL_KEY- Virtual key for managed provider credentialsPORTKEY_PROVIDER+PORTKEY_AUTHORIZATION- Direct provider authPORTKEY_CONFIG- Config ID for complex routing
Optional:
PORTKEY_CUSTOM_HOST- Custom host URL (with provider auth)PORTKEY_BASE_URL- Base URL for the APIPORTKEY_TIMEOUT_SECS- Request timeout in secondsPORTKEY_TRACE_ID- Trace ID for request trackingPORTKEY_CACHE_NAMESPACE- Cache namespacePORTKEY_CACHE_FORCE_REFRESH- Force cache refresh (true/false)
§Examples
# Virtual key authentication
export PORTKEY_API_KEY=your-portkey-api-key
export PORTKEY_VIRTUAL_KEY=your-virtual-key
# Provider authentication
export PORTKEY_API_KEY=your-portkey-api-key
export PORTKEY_PROVIDER=openai
export PORTKEY_AUTHORIZATION="Bearer sk-..."
# Config-based authentication
export PORTKEY_API_KEY=your-portkey-api-key
export PORTKEY_CONFIG=pc-config-123Trait Implementations§
Source§impl Clone for PortkeyConfig
impl Clone for PortkeyConfig
Source§fn clone(&self) -> PortkeyConfig
fn clone(&self) -> PortkeyConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more