Skip to content

refactor: decouple providers from core-only types#7162

Merged
AntoineToussaint merged 8 commits intomainfrom
decouple-providers-from-core-types
Apr 10, 2026
Merged

refactor: decouple providers from core-only types#7162
AntoineToussaint merged 8 commits intomainfrom
decouple-providers-from-core-types

Conversation

@AntoineToussaint
Copy link
Copy Markdown
Member

@AntoineToussaint AntoineToussaint commented Apr 1, 2026

Summary

  • Create tensorzero-http crate: Extract the shared HTTP client (TensorzeroHttpClient, event source, response wrappers) from tensorzero-core into its own crate, enabling reuse across crates without depending on core
  • Move credential types to tensorzero-inference-types: Extract CredentialLocation, ModelProviderRequestInfo, and related types into credentials.rs in the shared inference-types crate
  • Introduce ProviderInferenceRequest: New provider-facing request type that mirrors ModelProviderRequest but omits otlp_config (which no provider ever used)
  • Decouple InferenceProvider trait from ModelProvider: Change trait signatures to accept &ModelProviderRequestInfo instead of &ModelProvider, and ProviderInferenceRequest instead of ModelProviderRequest
  • Update all ~20 provider implementations: Mechanical updates to use the new types, removing all otlp_config: _ destructuring patterns
  • Replace free functions with proper From impls: Add tensorzero-stored-config as a dependency of tensorzero-inference-types to enable proper From impls for all stored config conversions (ExtraBody, ExtraHeaders, CredentialLocation, EndpointLocation, etc.), eliminating 14 ugly free functions
  • Fix danger_accept_invalid_certs CodeQL alert: Switch from runtime cfg!() to compile-time #[cfg(feature = "e2e_tests")] so the code is completely excluded from production builds

This is a prerequisite for extracting providers into their own tensorzero-providers crate. Providers now only depend on types from shared crates (tensorzero-inference-types, tensorzero-types, tensorzero-error, tensorzero-http), with no remaining imports from crate::model::ModelProvider or crate::cache::ModelProviderRequest.

CodeQL note

CodeQL flags a danger_accept_invalid_certs alert, but this is a stale/false positive. The code is now behind #[cfg(feature = "e2e_tests")] — it is completely excluded from production builds at compile time. The alert needs to be manually dismissed in the security tab.

Test plan

  • cargo check --all-targets --all-features
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo fmt
  • All CI checks pass (General Checks green)

🤖 Generated with Claude Code

@AntoineToussaint AntoineToussaint force-pushed the decouple-providers-from-core-types branch from 1fe1942 to bce1ad3 Compare April 2, 2026 15:10
@AntoineToussaint AntoineToussaint changed the base branch from extract-model-inference-request to move-rate-limiting-types-to-types April 3, 2026 18:49
@AntoineToussaint AntoineToussaint changed the base branch from move-rate-limiting-types-to-types to extract-model-inference-request April 3, 2026 19:03
Base automatically changed from extract-model-inference-request to main April 7, 2026 23:46
…o-types

Rate limiting config types (RateLimitResource, RateLimitingConfigScopes,
TagRateLimitingConfigScope, etc.) are domain types that belong in
tensorzero-types, not tensorzero-error. They were in the error crate
only because ErrorDetails variants reference them.

All 3 call sites updated to import from tensorzero_types directly.
No re-export shim needed.

This unblocks implementing From<StoredRateLimitingConfig> in the
stored-config crate (which depends on tensorzero-types but not
tensorzero-error).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AntoineToussaint AntoineToussaint changed the base branch from main to move-rate-limiting-types-to-types April 8, 2026 13:31
Extract shared types and HTTP client into separate crates, and decouple
provider implementations from core-internal types (ModelProvider,
OtlpConfig). This is a prerequisite for extracting providers into
their own crate.

Key changes:
- Create tensorzero-http crate with the shared HTTP client
- Move credential types and ModelProviderRequestInfo to tensorzero-inference-types
- Introduce ProviderInferenceRequest (like ModelProviderRequest without otlp_config)
- Update InferenceProvider trait to use &ModelProviderRequestInfo instead of &ModelProvider
- Update all ~20 provider implementations to use the new types
- Core converts at the dispatch boundary before calling into providers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AntoineToussaint AntoineToussaint force-pushed the decouple-providers-from-core-types branch from 2adba13 to 782a122 Compare April 8, 2026 14:23
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Base automatically changed from move-rate-limiting-types-to-types to main April 8, 2026 15:15
…nversions

Add tensorzero-stored-config as a dependency of tensorzero-inference-types
so that From<StoredExtraBodyConfig> for ExtraBodyConfig (and vice versa)
can be implemented directly on the types. This eliminates the ugly free
functions (extra_body_config_from_stored, extra_body_config_to_stored, etc.)
that were needed as an orphan rule workaround.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment thread crates/tensorzero-http/src/lib.rs Dismissed
@AntoineToussaint AntoineToussaint force-pushed the decouple-providers-from-core-types branch from c768b5b to b265de1 Compare April 8, 2026 20:39
…nversions

Add tensorzero-stored-config as a dependency of tensorzero-inference-types
so that From impls can be implemented directly on the types. This eliminates
all the ugly free functions that were needed as orphan rule workarounds:

- extra_body_config_from_stored / extra_body_config_to_stored
- extra_headers_config_from_stored / extra_headers_config_to_stored
- credential_location_from_stored / credential_location_to_stored
- credential_location_with_fallback_from_stored / credential_location_with_fallback_to_stored
- credential_location_or_hardcoded_from_stored / credential_location_or_hardcoded_to_stored
- endpoint_location_from_stored / endpoint_location_to_stored
- stored_api_key_defaults_from_credential_location
- stored_gcp_credential_defaults_from_credential_location

All call sites reverted to idiomatic .map(Type::from) / .map(Into::into).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AntoineToussaint AntoineToussaint force-pushed the decouple-providers-from-core-types branch from b265de1 to 20af373 Compare April 8, 2026 20:53
The danger_accept_invalid_certs call was guarded by cfg!(feature = "e2e_tests")
which is a runtime check — the code still compiles into production builds and
CodeQL flags it. Switch to #[cfg(feature = "e2e_tests")] so the code is
completely excluded from non-test builds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AntoineToussaint AntoineToussaint force-pushed the decouple-providers-from-core-types branch from d3f21b7 to 0e4f818 Compare April 9, 2026 14:05
@shuyangli
Copy link
Copy Markdown
Contributor

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e4f81831c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/tensorzero-http/src/lib.rs
shuyangli
shuyangli previously approved these changes Apr 9, 2026
Copy link
Copy Markdown
Contributor

@shuyangli shuyangli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a cursory look and I think the main thing is a bunch of types moving into tensorzero-inference-types and the http client moving into tensorzero-http. looks fine.

Comment thread crates/tensorzero-http/src/lib.rs Dismissed
GabrielBianconi
GabrielBianconi previously approved these changes Apr 9, 2026
Copy link
Copy Markdown
Member

@GabrielBianconi GabrielBianconi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blind

…tra-body-headers

# Conflicts:
#	crates/tensorzero-core/src/http.rs
This was a working copy from exploration, not ready for commit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AntoineToussaint AntoineToussaint added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit 4a8199c Apr 10, 2026
224 of 236 checks passed
@AntoineToussaint AntoineToussaint deleted the decouple-providers-from-core-types branch April 10, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants