[NA] [SDK] fix: map Hermes provider names to Opik canonical so cost is computed - #21
Merged
Merged
Conversation
…s computed Opik only calculates/attributes LLM cost when a span's provider is one it recognizes (opik.types.LLMProvider: openai, anthropic, groq, bedrock, google_ai, google_vertexai, anthropic_vertexai). The plugin passed Hermes' own provider string straight through — e.g. 'openai-api' — which Opik doesn't recognize, so cost was silently not computed on LLM spans. Add providers.to_opik_provider(): maps known Hermes identifiers (openai-api / openai_responses / codex_responses -> openai, anthropic_messages -> anthropic, gemini/google -> google_ai, vertex -> google_vertexai, bedrock* -> bedrock, groq) to Opik canonical names; already-canonical or unrecognized (custom/user-defined) providers pass through unchanged so cost calc degrades gracefully. Applied only to the span's provider field — Hermes' own pricing path (usage.py) keeps using the raw Hermes name, which it understands. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the single openai end-to-end test with a parametrized one that drives a real turn through the hooks for each provider (openai-api/_responses/ codex_responses, anthropic*, gemini/google, vertex, bedrock*, groq) and asserts the emitted LLM span carries Opik's canonical name. Plus an unknown-provider pass-through-through-hooks case. Proves the whole plugin path per provider with no real keys; whether Opik then costs each is Opik's job (we stop at the span boundary). Suite: 100 passed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
JetoPistola
marked this pull request as ready for review
July 6, 2026 15:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Details
Reviewer feedback: the plugin wrote Hermes' provider string (e.g.
openai-api) straight onto the Opik LLM span, but Opik only computes/attributes cost when the provider is one it recognizes (opik.types.LLMProvider:openai,anthropic,groq,bedrock,google_ai,google_vertexai,anthropic_vertexai). Soopenai-api→ Opik couldn't calculate cost.Add
providers.to_opik_provider()and apply it to the span'sproviderfield at both LLM-span creation sites (hooks.py):openai-api/openai_responses/codex_responses/azure-openai→openai;anthropic-api/anthropic_messages→anthropic;gemini/google→google_ai;vertex→google_vertexai;bedrock*→bedrock;groq→groq.None/empty →None.Scope: mapping is applied only to the value written to Opik's span
providerfield (what unlocks Opik's cost calc). Hermes' own pricing path (usage.py→agent.usage_pricing) keeps using the raw Hermes provider name, since Hermes understands its own identifiers — mapping there could break it.Change checklist
Issues
NA — addresses reviewer feedback on the plugin's Opik cost attribution.
Testing
tests/test_providers.py(20 tests): the mapping table, already-canonical pass-through, unknown pass-through, case/whitespace, None/empty, and an end-to-end check that a turn withprovider="openai-api"produces an LLM span withprovider="openai".ruff check+ruff format --checkclean (CI scope).Documentation
N/A — internal mapping; no API/behavior change beyond correct cost attribution.
🤖 Generated with Claude Code
Generated description
graph LR on_post_llm_call_("on_post_llm_call"):::modified to_opik_provider_("to_opik_provider"):::added on_api_request_error_("on_api_request_error"):::modified on_post_llm_call_ -- "Normalizes Hermes provider names so Opik costs compute correctly." --> to_opik_provider_ on_api_request_error_ -- "Normalizes provider during error span recording for consistent Opik matching." --> to_opik_provider_ classDef added stroke:#15AA7A classDef removed stroke:#CD5270 classDef modified stroke:#EDAC4C linkStyle default stroke:#CBD5E1,font-size:13pxMap Hermes provider identifiers through
providers.to_opik_providerbefore writing to Opik spans so recognized cost attribution runs on canonicalopik.types.LLMProvidernames. Cover canonical, custom, and whitespace variants plus the hooks’ LLM span path to ensure the mapping behaves correctly.providers.to_opik_providerand the hook flow against known, canonical, unknown, and whitespace/case variants plus an end-to-end turn so spans emit the expected provider names.Modified files (1)
Latest Contributors(1)
providers.to_opik_providerbefore setting the spanproviderin the hooks so Opik recognizes canonicalopik.types.LLMProvidernames for cost attribution.Modified files (2)
Latest Contributors(1)