1use crate::auth::{AuthStorage, Credential};
2use crate::config::provider::ProviderId;
3use crate::error::{Error, Result};
4
5pub async fn import_api_key(
7 provider_id: &ProviderId,
8 api_key: String,
9 storage: &dyn AuthStorage,
10) -> Result<()> {
11 if api_key.is_empty() {
12 return Err(Error::Configuration("API key cannot be empty".to_string()));
13 }
14
15 storage
16 .set_credential(
17 &provider_id.storage_key(),
18 Credential::ApiKey { value: api_key },
19 )
20 .await
21 .map_err(|e| Error::Configuration(format!("Failed to store API key: {e}")))?;
22
23 Ok(())
24}