MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / resolve_provider_route

Function resolve_provider_route

crates/openshell-server/src/inference.rs:658–758  ·  view source on GitHub ↗
(
    provider: &Provider,
    model_id: &str,
)

Source from the content-addressed store, hash-verified

656}
657
658fn resolve_provider_route(
659 provider: &Provider,
660 model_id: &str,
661) -> Result<ResolvedProviderRoute, Status> {
662 let raw_provider_type = provider.r#type.trim();
663 let provider_type = normalize_provider_type(raw_provider_type)
664 .map_or_else(|| raw_provider_type.to_ascii_lowercase(), str::to_string);
665
666 let profile = openshell_core::inference::profile_for(&provider_type).ok_or_else(|| {
667 Status::invalid_argument(format!(
668 "provider '{name}' has unsupported type '{raw_provider_type}' for cluster inference \
669 (supported: openai, anthropic, nvidia, deepinfra, google-vertex-ai, aws-bedrock)",
670 name = provider.object_name()
671 ))
672 })?;
673
674 // Profiles with `auth: None` are bridge-fronted — the upstream
675 // authenticates itself, so the router doesn't need a credential at
676 // route-resolution time. Today this is `aws-bedrock`.
677 let api_key = if matches!(profile.auth, openshell_core::inference::AuthHeader::None) {
678 String::new()
679 } else {
680 find_provider_api_key(
681 provider,
682 profile.credential_key_names,
683 if provider_type == "google-vertex-ai" {
684 CredentialLookup::PreferredOnly
685 } else {
686 CredentialLookup::PreferredThenAny
687 },
688 )
689 .ok_or_else(|| {
690 Status::invalid_argument(format!(
691 "provider '{name}' has no usable API key credential",
692 name = provider.object_name()
693 ))
694 })?
695 };
696
697 // Vertex AI requires a model-aware URL; delegate to specialised resolver.
698 if provider_type == "google-vertex-ai" {
699 let route = resolve_vertex_ai_route(
700 &provider.config,
701 model_id,
702 provider.object_name(),
703 &api_key,
704 profile,
705 )?;
706 return Ok(ResolvedProviderRoute {
707 provider_type,
708 route,
709 });
710 }
711
712 // AWS Bedrock encodes the model in the URL path
713 // (`/model/<id>/invoke`), so the model id is interpolated directly
714 // into a path segment by the router. Validate up front so the route
715 // store cannot hold a model id that would produce ambiguous or

Calls 8

normalize_provider_typeFunction · 0.85
profile_forFunction · 0.85
find_provider_api_keyFunction · 0.85
resolve_vertex_ai_routeFunction · 0.85
object_nameMethod · 0.80
is_emptyMethod · 0.45