Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(provider): add endpoint redaction utility

Steven Enamakel1341b33e9c62
diff --git a/crates/openhuman-core/src/inference/provider/factory.rs b/crates/openhuman-core/src/inference/provider/factory.rs
index 00455cf810..2b48b4ad61 100644
--- a/crates/openhuman-core/src/inference/provider/factory.rs
+++ b/crates/openhuman-core/src/inference/provider/factory.rs
@@ -30,7 +30,9 @@ pub use chat_model::{
create_chat_model_from_string, create_chat_model_from_string_with_model_id,
create_chat_model_in, create_chat_model_with_model_id_in, probe_inference_readiness,
};
-pub(crate) use credentials::{openai_bearer_is_oauth, resolve_codex_routing};
+pub(crate) use credentials::{
+ openai_bearer_is_oauth, redact_endpoint_origin, resolve_codex_routing,
+};
pub use credentials::{auth_key_for_slug, lookup_key_for_slug};
pub(crate) use discovery::{model_limits_request, model_limits_request_for};
pub(crate) use local_runtime::create_local_chat_model_from_string;
@@ -101,18 +103,6 @@ use tinyinference_llm::providers::openai::codex::{
OPENAI_CODEX_ORIGINATOR, OPENAI_CODEX_ORIGINATOR_HEADER,
};
-/// Redact a configured endpoint to its origin for host diagnostics.
-///
-/// TinyInference's sanitizer keeps URL paths for routing diagnostics, while
-/// OpenHuman endpoints may carry credentials in path segments. Keep this host
-/// log policy origin-only and never fall back to the unparsed input.
-pub fn redact_endpoint_origin(endpoint: &str) -> String {
- let Ok(url) = reqwest::Url::parse(endpoint.trim()) else {
- return "<endpoint>".to_string();
- };
- tinyinference_core::sanitize::redact_url(&url.origin().ascii_serialization())
-}
-
/// Sentinel meaning "use the OpenHuman backend session JWT".
pub const PROVIDER_OPENHUMAN: &str = "openhuman";
/// Provider id used for the managed OpenHuman inference backend.
diff --git a/crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs b/crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs
index dab212ccc5..88f294148c 100644
--- a/crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs
@@ -49,7 +49,7 @@ fn spec_keeps_the_slug_as_provider_name_and_picks_the_kind_from_auth() {
}
#[test]
-fn managed_jwt_style_never_maps_onto_the_registry() {
+fn auth_style_conversion_maps_managed_jwt_to_the_registry_neutral_style() {
let _: tinyinference_llm::providers::openai::AuthStyle = AuthStyle::Bearer.into();
assert_eq!(
tinyinference_llm::providers::openai::AuthStyle::from(AuthStyle::OpenhumanJwt),
diff --git a/crates/openhuman-core/src/inference/provider/factory/credentials.rs b/crates/openhuman-core/src/inference/provider/factory/credentials.rs
index b866712ec4..13386e32ef 100644
--- a/crates/openhuman-core/src/inference/provider/factory/credentials.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/credentials.rs
@@ -12,6 +12,18 @@ pub fn auth_key_for_slug(slug: &str) -> String {
format!("provider:{slug}")
}
+/// Redact a configured endpoint to its origin for host diagnostics.
+///
+/// TinyInference's sanitizer keeps URL paths for routing diagnostics, while
+/// OpenHuman endpoints may carry credentials in path segments. Keep this host
+/// log policy origin-only and never fall back to the unparsed input.
+pub(crate) fn redact_endpoint_origin(endpoint: &str) -> String {
+ let Ok(url) = reqwest::Url::parse(endpoint.trim()) else {
+ return "<endpoint>".to_string();
+ };
+ tinyinference_core::sanitize::redact_url(&url.origin().ascii_serialization())
+}
+
/// Whether the openai bearer that [`lookup_key_for_slug`] resolves is an OAuth
/// (Codex-subscription) credential rather than a standard API key.
///
diff --git a/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs b/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
index 6db1c76e6e..e922f8bac7 100644
--- a/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
@@ -360,6 +360,37 @@ fn create_chat_model_routes_plain_bearer_cloud_slug_to_crate_native() {
assert!(profile.tool_calling);
}
+#[test]
+fn unmanaged_openhuman_jwt_route_never_builds_a_direct_unauthenticated_model() {
+ let _guard = crate::inference::inference_test_guard();
+ let mut config = Config::default();
+ config.cloud_providers.push(CloudProviderCreds {
+ id: "p_managed".to_string(),
+ slug: "managed".to_string(),
+ label: "Managed".to_string(),
+ endpoint: "https://api.example/v1".to_string(),
+ auth_style: AuthStyle::OpenhumanJwt,
+ ..Default::default()
+ });
+
+ let error = try_create_cloud_slug_chat_model_from_string_with_native_tools(
+ "chat",
+ "managed:model",
+ &config,
+ true,
+ &EgressLedger::none(),
+ )
+ .expect("configured slug")
+ .expect_err("unregistered managed credentials must not reach the direct registry");
+
+ assert!(
+ error
+ .to_string()
+ .contains("hosted cloud authentication is unavailable"),
+ "unexpected error: {error}"
+ );
+}
+
#[test]
fn turn_model_route_metadata_uses_post_remap_cloud_model() {
let _guard = crate::inference::inference_test_guard();