MCPcopy Create free account
hub / github.com/enowdev/enowX-Coder / fetch_openai_models

Function fetch_openai_models

src-tauri/src/services/model_service.rs:55–87  ·  view source on GitHub ↗
(base_url: &str, api_key: Option<&str>)

Source from the content-addressed store, hash-verified

53}
54
55async fn fetch_openai_models(base_url: &str, api_key: Option<&str>) -> AppResult<Vec<String>> {
56 let url = format!("{}/models", base_url.trim_end_matches('/'));
57 let client = http_client::request_client()?;
58 let mut req = client.get(&url);
59
60 if let Some(key) = api_key {
61 if !key.is_empty() {
62 req = req.bearer_auth(key);
63 }
64 }
65
66 let resp = req
67 .send()
68 .await
69 .map_err(|e| AppError::Internal(format!("Failed to fetch models: {e}")))?;
70
71 if !resp.status().is_success() {
72 let status = resp.status();
73 let body = resp.text().await.unwrap_or_default();
74 return Err(AppError::Internal(format!(
75 "Models endpoint returned {status}: {body}"
76 )));
77 }
78
79 let list: ModelList = resp
80 .json()
81 .await
82 .map_err(|e| AppError::Internal(format!("Failed to parse models response: {e}")))?;
83
84 let mut ids: Vec<String> = list.data.into_iter().map(|m| m.id).collect();
85 ids.sort();
86 Ok(ids)
87}
88
89/// Fetch models from an Anthropic-format endpoint.
90///

Callers 1

list_modelsFunction · 0.85

Calls 2

request_clientFunction · 0.85
sendMethod · 0.80

Tested by

no test coverage detected