Skip to content

Added OpenRouter support#8

Merged
ishaan-jaff merged 2 commits intoBerriAI:mainfrom
zakhar-kogan:main
Jul 28, 2023
Merged

Added OpenRouter support#8
ishaan-jaff merged 2 commits intoBerriAI:mainfrom
zakhar-kogan:main

Conversation

@zakhar-kogan
Copy link
Contributor

Features

  • Added OpenRouter support as it gives access to GPT-4, PaLM-2 and Claude 2 without additional surcharges;
  • Added support for .env files and enclosed an example.

@zakhar-kogan zakhar-kogan changed the title Added openrouter.ai support Added OpenRouter support Jul 28, 2023
@krrishdholakia
Copy link
Member

PR under review ✅

Hope to revert by tonight.

Copy link
Member

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

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

thanks for the contribution, looks awesome. It's good to merge, but small nit: In completion_test can you leave all the other tests uncommented

print(response)

# # openai call
# response = completion(model="gpt-3.5-turbo", messages=messages)
Copy link
Member

Choose a reason for hiding this comment

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

can we leave all the other tests uncommented

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do in ~15 minutes. Thanks for reviewing 🧡

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uncommented + deleted the unneeded testos.py (my bad) 🥲

One question - I could try implementing everything using pattern matching. Should I try that, or we'll lose backward compatibility this way?

Copy link
Member

Choose a reason for hiding this comment

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

let's address pattern matching in a separate PR

@ishaan-jaff ishaan-jaff merged commit 7126246 into BerriAI:main Jul 28, 2023
@seonghobae
Copy link
Contributor

PR checks evidence (sync upstream)

Required checks

gh pr checks --required --watch --fail-fast
Output
no checks reported on the 'main' branch

Merge state

gh pr view --json mergeStateStatus,mergeable
Output
{"mergeStateStatus":"UNKNOWN","mergeable":"UNKNOWN"}

Rulesets / Branch policy

gh api "repos/BerriAI/litellm/rules/branches/main" || gh api "repos/BerriAI/litellm/branches/main/protection"
Output
[]

Code scanning

gh api "/repos/BerriAI/litellm/code-scanning/analyses?pr=8"
gh api "/repos/BerriAI/litellm/code-scanning/alerts?pr=8&state=open"
Output
{"message":"You are not authorized to read code scanning alerts.","documentation_url":"https://docs.github.com/rest/code-scanning/code-scanning#list-code-scanning-analyses-for-a-repository","status":"403"}gh: You are not authorized to read code scanning alerts. (HTTP 403)
gh: This API operation needs the "delete_repo" scope. To request it, run:  gh auth refresh -h github.com -s delete_repo
{"message":"You are not authorized to read code scanning alerts.","documentation_url":"https://docs.github.com/rest/code-scanning/code-scanning#list-code-scanning-alerts-for-a-repository","status":"403"}gh: You are not authorized to read code scanning alerts. (HTTP 403)
gh: This API operation needs the "delete_repo" scope. To request it, run:  gh auth refresh -h github.com -s delete_repo

Check-runs

gh api "/repos/BerriAI/litellm/commits/404ce961a7e8b71c24fd8c2130a58be753f0e2a4/check-runs"
Output
{"total_count":0,"check_runs":[]}

(Exit code: 1)

Harshit28j added a commit to Harshit28j/litellm that referenced this pull request Mar 6, 2026
…il traces

- Remove redundant set_attributes() call from raw_gen_ai_request spans so they
  only contain provider-specific llm.{provider}.{param} attributes (Issue #3)
- Replace full set_attributes() on litellm_proxy_request with minimal attributes
  (model, call_type, response.id) when litellm_request child span exists (Issue #4)
- Skip guardrail span creation when no parent context exists to prevent orphaned
  root-level traces in the "All Spans" view (Issue #5)
- Fall back to litellm_call_id for gen_ai.response.id when response object has no
  id field (EmbeddingResponse, ImageResponse) (Issue BerriAI#8)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Harshit28j added a commit to Harshit28j/litellm that referenced this pull request Mar 6, 2026
…onse IDs

Addresses 4 critical OpenTelemetry span issues in LiteLLM:

Issue #3: Remove redundant attributes from raw_gen_ai_request spans
- Removed self.set_attributes() call that was duplicating all parent span
  attributes (gen_ai.*, metadata.*) onto the raw span
- Raw span now only contains provider-specific llm.{provider}.* attributes
- Reduces storage and eliminates search confusion from duplicate data

Issue #4: Prevent attribute duplication on litellm_proxy_request parent span
- When litellm_request child span exists, removed redundant
  set_attributes() call on the parent proxy span
- Child span already carries all attributes; parent duplication doubles
  storage and complicates search

Issue #5: Fix orphaned guardrail traces
- Guardrail spans were created with context=None when no parent proxy span
  existed, resulting in orphaned root spans (separate trace_id)
- Added _resolve_guardrail_context() helper to ensure guardrails always
  have a valid parent (litellm_request or proxy span)
- Applied fix to both _handle_success and _handle_failure paths

Issue BerriAI#8: Add gen_ai.response.id for embeddings and image generation
- EmbeddingResponse and ImageResponse types don't have provider response IDs
- Added fallback to standard_logging_payload["id"] (litellm call ID) for
  correlation across LiteLLM UI, Phoenix traces, and provider logs
- Completions still use provider ID (e.g. "chatcmpl-xxx") when available

Tests added:
- TestRawSpanAttributeIsolation: Verify raw span has no gen_ai/metadata attrs
- TestNoParentSpanDuplication: Verify parent span doesn't get duplicated attrs
- TestGuardrailSpanParenting: Verify guardrails are children (not orphaned)
- TestResponseIdFallback: Verify response ID set for all call types

All existing OTEL tests pass (73 passed, 14 pre-existing protocol failures).

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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.

4 participants