1use crate::api::ProviderKind;
2use crate::auth::{AuthStorage, Credential};
3use crate::error::{Error, Result};
4
5pub async fn import_api_key(
7 provider: ProviderKind,
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(&provider.to_string(), Credential::ApiKey { value: api_key })
17 .await
18 .map_err(|e| Error::Configuration(format!("Failed to store API key: {e}")))?;
19
20 Ok(())
21}