agcodex_core/
embeddings_capability.rs1use crate::config::Config;
6use agcodex_login::OPENAI_API_KEY_ENV_VAR;
7use agcodex_login::get_auth_file;
8use agcodex_login::try_read_auth_json;
9
10pub fn can_use_openai_embeddings(config: &Config) -> bool {
16 if std::env::var(OPENAI_API_KEY_ENV_VAR)
18 .map(|v| !v.trim().is_empty())
19 .unwrap_or(false)
20 {
21 return true;
22 }
23
24 let auth_file = get_auth_file(&config.codex_home);
26 if let Ok(auth) = try_read_auth_json(&auth_file)
27 && auth
28 .openai_api_key
29 .as_deref()
30 .map(|s| !s.trim().is_empty())
31 .unwrap_or(false)
32 {
33 return true;
34 }
35
36 false
37}
38
39pub fn openai_embeddings_unavailable_reason(config: &Config) -> Option<String> {
41 if can_use_openai_embeddings(config) {
42 return None;
43 }
44 Some("OpenAI embeddings require an OPENAI_API_KEY. ChatGPT login tokens do not grant API access.".to_string())
45}