Skip to content

Commit 1c3fc5b

Browse files
fix(providers): address gator review findings for DeepInfra provider
- Narrow build_backend_url /v1 dedupe to URLs whose path component is exactly /v1 or starts with /v1/ — prevents regression on proxy endpoints where /v1 is buried deeper (e.g. /api/v1/openai); add regression test for the nested proxy path case - Add deepinfra provider plugin with DEEPINFRA_API_KEY discovery, registered in ProviderRegistry so known_types() and TUI include it - Add deepinfra to unsupported-inference-provider error message in openshell-server for accurate user-facing debugging guidance - Add deepinfra to openai_compatible_profiles_include_embeddings test to lock in the OpenAI-compatible protocol contract Signed-off-by: Milos Milutinovic <[email protected]>
1 parent b9a714f commit 1c3fc5b

6 files changed

Lines changed: 47 additions & 7 deletions

File tree

‎crates/openshell-core/src/inference.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ mod tests {
333333

334334
#[test]
335335
fn openai_compatible_profiles_include_embeddings() {
336-
for provider_type in ["openai", "nvidia"] {
336+
for provider_type in ["openai", "nvidia", "deepinfra"] {
337337
let profile = profile_for(provider_type).expect("provider profile should exist");
338338
assert!(
339339
profile.protocols.contains(&"openai_embeddings"),

‎crates/openshell-providers/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl ProviderRegistry {
116116
registry.register(providers::openai::SPEC);
117117
registry.register(providers::anthropic::SPEC);
118118
registry.register(providers::nvidia::SPEC);
119+
registry.register(providers::deepinfra::SPEC);
119120
registry.register(providers::gitlab::SPEC);
120121
registry.register(providers::github::SPEC);
121122
registry.register(providers::outlook::OutlookProvider);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use crate::ProviderDiscoverySpec;
5+
6+
pub const SPEC: ProviderDiscoverySpec = ProviderDiscoverySpec {
7+
id: "deepinfra",
8+
credential_env_vars: &["DEEPINFRA_API_KEY"],
9+
};
10+
11+
test_discovers_env_credential!(
12+
discovers_deepinfra_env_credentials,
13+
"DEEPINFRA_API_KEY",
14+
"di-test-123"
15+
);

‎crates/openshell-providers/src/providers/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod anthropic;
3434
pub mod claude;
3535
pub mod codex;
3636
pub mod copilot;
37+
pub mod deepinfra;
3738
pub mod generic;
3839
pub mod github;
3940
pub mod gitlab;

‎crates/openshell-router/src/backend.rs‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -768,11 +768,20 @@ fn build_provider_url(
768768

769769
fn build_backend_url(endpoint: &str, path: &str) -> String {
770770
let base = endpoint.trim_end_matches('/');
771-
// Strip the /v1 prefix from the request path when the base URL already
772-
// contains a /v1 segment — either ending with it (e.g. openai, nvidia)
773-
// or containing it internally (e.g. deepinfra: /v1/openai).
774-
let base_has_v1 = base.ends_with("/v1") || base.contains("/v1/");
775-
if base_has_v1 && (path == "/v1" || path.starts_with("/v1/")) {
771+
// Strip the /v1 prefix from the request path only when the base URL's
772+
// own path component is exactly /v1 (e.g. openai, nvidia: ".../v1") or
773+
// starts with /v1/ (e.g. deepinfra: ".../v1/openai"). This avoids
774+
// doubling /v1 for those providers while preserving the full path for
775+
// proxy endpoints where /v1 appears deeper in the path
776+
// (e.g. "https://proxy.example/api/v1/openai").
777+
let base_path_is_v1_rooted = base
778+
.find("://")
779+
.and_then(|i| base[i + 3..].find('/').map(|j| i + 3 + j))
780+
.is_some_and(|path_start| {
781+
let base_path = &base[path_start..];
782+
base_path == "/v1" || base_path.starts_with("/v1/")
783+
});
784+
if base_path_is_v1_rooted && (path == "/v1" || path.starts_with("/v1/")) {
776785
return format!("{base}{}", &path[3..]);
777786
}
778787

@@ -848,6 +857,20 @@ mod tests {
848857
);
849858
}
850859

860+
#[test]
861+
fn build_backend_url_preserves_v1_for_nested_proxy_path() {
862+
// A proxy whose base path has /v1 buried deeper (not at the root of
863+
// the path) must NOT have /v1 stripped — the full request path must
864+
// be appended so the upstream receives the correct API version prefix.
865+
assert_eq!(
866+
build_backend_url(
867+
"https://proxy.example/api/v1/openai",
868+
"/v1/chat/completions"
869+
),
870+
"https://proxy.example/api/v1/openai/v1/chat/completions"
871+
);
872+
}
873+
851874
fn test_route(endpoint: &str, protocols: &[&str], auth: AuthHeader) -> ResolvedRoute {
852875
ResolvedRoute {
853876
name: "inference.local".to_string(),

‎crates/openshell-server/src/inference.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ fn resolve_provider_route(
620620
let profile = openshell_core::inference::profile_for(&provider_type).ok_or_else(|| {
621621
Status::invalid_argument(format!(
622622
"provider '{name}' has unsupported type '{raw_provider_type}' for cluster inference \
623-
(supported: openai, anthropic, nvidia, google-vertex-ai)",
623+
(supported: openai, anthropic, nvidia, deepinfra, google-vertex-ai)",
624624
name = provider.object_name()
625625
))
626626
})?;

0 commit comments

Comments
 (0)